package com.tianqu.tms.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.enums.PlateNumberTypes;
import com.tianqu.tms.dto.BaseCarInfoDto;
import com.tianqu.tms.dto.ControlCarDto;
import com.tianqu.tms.dto.GatesInfoOutDto;
import com.tianqu.tms.dto.MarketCarGateInfoDto;
import com.tianqu.tms.dto.MarketCarHandleInfoDto;
import com.tianqu.tms.dto.MarketCarInfoChe300;
import com.tianqu.tms.dto.MarketCarInfoDto;
import com.tianqu.tms.dto.MarketCarServiceDto;
import com.tianqu.tms.dto.TempLicensePlate;
import com.tianqu.tms.dto.TransferAcceptedInfoDto;
import com.tianqu.tms.dto.TransferPersonalCarInfoDto;
import com.tianqu.tms.dto.TroubleCarInfoDto;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.core.base.Logger;

public class CarDaoImp extends ViewListDao implements CarDao  {
	private static Logger logger = Logger.getLogger(CarDaoImp.class);//log
	

	protected final String[] sortKeyList = new String[]{"ID","SERIAL","TRANSFERSERIAL","LICENSEPLATE","VIN","REALNAME","CARSCORE","INSERTTIME"};//待入库列表排序

	protected final String[] seniorSortKeyList = new String[]{"SERIAL","SERIAL","CARNAME","LICENSEPLATE","VIN","GEARBOXNAME","DISPLACEMENT","SHORTNAME","INSERTTIME"};//高级搜索排序 
	
	protected final String[] gatesInfoIOKeyList = new String[]{"ID","CARDID","SHOPNAME","CARNAME","CARLICENSE","IMGPATH","CHANNELNAME","INTIME","OUTTIME"};//进出库排序   

	protected final String[] gatesInfoInputDetailList = new String[]{"SHOPNAME","SHOPNAME","CARLICENSE","IMGPATH","CAROWNER","INTIME"};//统计排序 按入场时间排序 
	
	protected final String[] carPhotoSortKeyList = new String[]{"SERIAL","SERIAL","LICENSEPLATE","PHOTO_1","PHOTO_2","PHOTO_3","PHOTO_4","PRICE","MILEAGE","INSERTTIME,UPDATETIME"};
	
	protected final String[] memberCarListZero = new String[]{"SERIAL","SERIAL","LICENSEPLATE","CARNAME","PRICE","MILEAGE","STORAGETIME","REGISTERSTATUS","STATUS","INSERTTIME","INSERTTIME"};
	
	protected final String[] memberCarListOne = new String[]{"SERIAL","SERIAL","LICENSEPLATE","CARNAME","DISPLACEMENT","NEWCAROWNER","AGENCYPRICE","EXTENDEDPRICE","AGENTTIME","AGENTTIME"};
	
	protected final String[] memberCarListThree = new String[]{"SERIAL","SERIAL","LICENSEPLATE","CARNAME","DISPLACEMENT","NEWCAROWNER","SERIAL","SERIAL","SERIAL","SERIAL","INSERTTIME"};
	
	protected final String[] memberCarListFour = new String[]{"SERIAL","SERIAL","LICENSEPLATE","CARNAME","DISPLACEMENT","NEWCAROWNER","SERIAL","SERIAL","SERIAL","SERIAL","INSERTTIME"};
	
	protected final String[] inoutSortKeyList = new String[]{"SERIAL","SERIAL","LICENSEPLATE","CARNAME","THREADTYPE","GATETYPE","CARPHOTO","THREADSTATUS","INSERTTIME","CHECKFLAG","LICENSECOLOR","COLOR"};//高级搜索进出库查询 
	
	protected final String[] spericalCarList = new String[]{"ID","SERIAL","SERIAL","VIN","LICENSEPLATE","CARNAME","INSERTTIME"};//特殊车辆查询
	protected final String[] spericalCarOldList = new String[]{"ID","SERIAL","SERIAL","VIN","LICENSEPLATE","CARNAME","ACCPETTIME"};//特殊车辆查询
	protected CarDaoImp(int pageNo,
			int maxIndex,int sortKey,boolean asc) throws TmsDaoException{
		super( pageNo,maxIndex, sortKey, asc);
	}
	
	
	public CarDaoImp() throws TmsDaoException{
		super();
	}


	/* 
	 * 载入待入库车辆
	 */
	@Override
	public List<ControlCarDto> loadControlCarList() throws TmsDaoException {
		List<ControlCarDto> innerCarList = new ArrayList<ControlCarDto>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ");
		sql.append(" MARKET.ID AS ID,");
		sql.append(" MARKET.SERIAL AS SERIAL,");
		sql.append(" MARKET.LICENSEPLATE AS LICENSEPLATE,");
		sql.append(" MEMBER.REALNAME AS REALNAME,");
		sql.append(" TRANSFER.SERIAL AS TRANSFERSERIAL,");
		sql.append(" MARKET.VIN AS VIN,");
		sql.append(" MARKET.INSERTTIME AS INSERTTIME, ");
		sql.append(" MARKET.CARSCORE AS CARSCORE");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" MARKET");
		sql.append(" LEFT JOIN  ");
		sql.append(TmsTableNames.TMS_MEMBER);
		sql.append(" MEMBER ");
		sql.append(" ON MEMBER.MEMBERID=MARKET.MEMBERID");
		sql.append(" LEFT JOIN  ");
		sql.append(TmsTableNames.TMS_TRANSFER_ACCEPTED_INFO);
		sql.append(" TRANSFER");
		sql.append(" ON TRANSFER.BASICCARID = MARKET.SERIAL");
		sql.append(" WHERE");
		sql.append(" MARKET.REGISTERSTATUS IN (1,2) ");
		sql.append(" AND MARKET.ENTRYSTATUS =1 ");
		sql.append(" AND MARKET.STATUS = 1");
		
		//排序方法
		sql.append(getOrderBySql(sortKeyList));
		
		try {
			ps = conn.prepareStatement(getSql(sql.toString()));
			
			rs = ps.executeQuery();
			ControlCarDto controlCarDto = null;
			int i=0;
			while (rs.next()) {
				controlCarDto = new ControlCarDto();
				controlCarDto.setId(rs.getLong("ID"));
				controlCarDto.setSerial(rs.getString("SERIAL")); 
				controlCarDto.setCarLicense(rs.getString("LICENSEPLATE"));
				controlCarDto.setMemberName(rs.getString("REALNAME"));
				controlCarDto.setInsertTime(DateUtil.getTimeByTimeStamp1(rs.getTimestamp("INSERTTIME")));	
				if(i%2 == 0){
					controlCarDto.setCssFlag(1);
				}else{
					controlCarDto.setCssFlag(2);
				}
				int num = (i+1)+(getPageNo()-1)*30;
				controlCarDto.setNum(num);
				controlCarDto.setTransferSerial(rs.getString("TRANSFERSERIAL"));
				controlCarDto.setVin(rs.getString("VIN"));
				controlCarDto.setCarScore(rs.getInt("CARSCORE"));
				innerCarList.add(controlCarDto);
				i++;
			}
			return innerCarList;
			
		} 
		
		catch (SQLException e) {
			throw new TmsDaoException(e.toString());
			
		} finally {
			super.close(rs, ps);
		}
		
	}
	/* 
	 * 根据VIN码查询车辆信息
	 */
	
	/* 
	 * 根据VIN码查询车辆信息
	 */
	
	@Override
	public MarketCarInfoDto findCarByVin(String vin) throws TmsDaoException {
		
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = new MarketCarInfoDto();
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ");
		sql.append("ID,");
		sql.append("SERIAL,");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("LICENSEPLATE,");
		sql.append("PRICE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("MEMBERID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("ATTRIBUTE,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("UPDATETIME,");
		sql.append("ATTESTSTATUS, ");
		sql.append("UPDATEUSERID, ");
		sql.append("VENDORID, ");
		sql.append("TEMPLICENSEPLATE ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" VIN=?");
		sql.append(" ORDER BY ID DESC");
		
		try {

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, vin);			
			rs = ps.executeQuery();
			int i =1;
			
			while (rs.next()) {
				if(i==2){
					break;
				}
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				marketCarInfoDto.setTempLicensePlate("TEMPLICENSEPLATE");
				i++;
			}
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		
	}
	
	@Override
	public List<MarketCarInfoDto> findCarListByVin(String vin) throws TmsDaoException {
		
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ");
		sql.append("ID,");
		sql.append("SERIAL,");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("LICENSEPLATE,");
		sql.append("PRICE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("MEMBERID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("ATTRIBUTE,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("UPDATETIME,");
		sql.append("ATTESTSTATUS, ");
		sql.append("UPDATEUSERID, ");
		sql.append("VENDORID, ");
		sql.append("TEMPLICENSEPLATE ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" VIN=?");
		sql.append(" ORDER BY ID DESC");
		
		List<MarketCarInfoDto> list = new ArrayList<MarketCarInfoDto>();
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, vin);			
			rs = ps.executeQuery();
			while (rs.next()) {
				MarketCarInfoDto marketCarInfoDto = new MarketCarInfoDto();
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				marketCarInfoDto.setTempLicensePlate(rs.getString("TEMPLICENSEPLATE"));
				list.add(marketCarInfoDto);
			}
			return list;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		
	}

	@Override
	public void saveMarketCarInfo(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("INSERT INTO ");
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
			sql.append("(");
			sql.append(" CAROWNER, ");
			sql.append(" CARNAME, ");			
			sql.append(" SERIAL, ");
			sql.append(" VIN, ");
			sql.append(" ENGINE, ");
			sql.append(" LICENSEPLATE, ");
			sql.append(" PRICE, ");
			sql.append(" COLOR, ");
			sql.append(" MODELCODE, ");
			sql.append(" VENDORCODE, ");
			sql.append(" REGDATE, ");
			sql.append(" YEARCAREFULPERIOD, ");
			sql.append(" DISPLACEMENT, ");
			sql.append(" JQX, ");
			sql.append(" CARUSE, ");
			sql.append(" CARTYPE, ");
			sql.append(" MILEAGE, ");
			sql.append(" GEARBOX, ");
			sql.append(" SENDCARDDATE, ");
			sql.append(" CARDTYPE, ");
			sql.append(" COUNTRYSTYLE, ");
			sql.append(" REGISTERCARDNO, ");
			sql.append(" COMPANYCONTACTPERSON, ");
			sql.append(" COMPANYCONTACTPHONE, ");
			sql.append(" CAROWNERIDCARDNO, ");
			sql.append(" VENDORID, ");
			sql.append(" BRANDID, ");
			sql.append(" CARSTYLEID, ");
			sql.append(" MEMBERID, ");
			sql.append(" FUELTYPE, ");
			sql.append(" LOADQUALITY, ");
			sql.append(" PASSENGER, ");
			sql.append(" OWNERPHONE, ");
			sql.append(" OWNERADDRESS, ");
			sql.append(" ATTRIBUTE, ");
			sql.append(" OWNERTYPE, ");
			sql.append(" OWNERORGNO, ");
			sql.append(" INSERTTIME, ");
			sql.append(" UPDATETIME, ");
			sql.append(" UPDATEUSERID, ");
			sql.append(" CARSCORE,");
			sql.append(" REGISTERSTATUS,");
			sql.append(" ENTRYSTATUS,");
			sql.append(" INSERTUSERID,");
			sql.append(" PHOTO_1,");
			sql.append(" PHOTO_2,");
			sql.append(" PHOTO_3,");
			sql.append(" PHOTO_4,");
			sql.append(" PHOTO_5,");
			sql.append(" PHOTO_6,");
			sql.append(" PHOTO_7,");
			sql.append(" PHOTO_8,");
			sql.append(" STATUS,");
			sql.append("STORAGETIME,");
			sql.append("ATTESTSTATUS");
			sql.append("  ) VALUES ( ");
			sql.append(" ?,?,?,?,?,?,?,?,?,?" +
						",?,?,?,?,?,?,?,?,?,?" +
						",?,?,?,?,?,?,?,?,?,?" +
						",?,?,?,?,?,?,?,SYSDATE(),SYSDATE(),?" +
						",?,?,?,?,?,?,?,?,?,?,?,?,?,SYSDATE(),? )");

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, dto.getCarOwner());
			ps.setString(2, dto.getCarName());
			ps.setString(3, dto.getSerial());
			ps.setString(4, dto.getVin());
			ps.setString(5, dto.getEngine());
			ps.setString(6, dto.getLicensePlate());
			ps.setDouble(7, dto.getPrice());
			ps.setInt(8, dto.getColor());
			ps.setString(9, dto.getModelCode());
			ps.setString(10, dto.getVendorCode());
			ps.setString(11, dto.getRegDate());
			ps.setString(12, dto.getYearCarefulPeriod());
			ps.setInt(13, dto.getDisplacement());
			ps.setString(14, dto.getJqx());
			ps.setInt(15, dto.getCarUse());
			ps.setInt(16, dto.getCarType());
			ps.setDouble(17, dto.getMileage());
			ps.setInt(18, dto.getGearbox());
			ps.setString(19, dto.getSendCardDate());
			ps.setInt(20, dto.getCardType());
			ps.setInt(21, dto.getCountryStyle());
			ps.setString(22, dto.getRegisterCardNo());
			ps.setString(23, dto.getCompanyContactPerson());
			ps.setString(24, dto.getCompanyContactPhone());
			ps.setString(25, dto.getCarOwnerIdCardNo());
			ps.setString(26, dto.getVendorId());
			ps.setString(27, dto.getBrandId());
			ps.setString(28, dto.getCarStyleId());
			ps.setInt(29, dto.getMemberId());
			ps.setInt(30, dto.getFuelType());
			ps.setInt(31, dto.getLoadquality());
			ps.setInt(32, dto.getPassenger());
			ps.setString(33, dto.getOwnerPhone());
			ps.setString(34, dto.getOwnerAddress());
			ps.setInt(35, dto.getAttribute());
			ps.setInt(36, dto.getOwnerType());
			ps.setString(37, dto.getOwnerOrgNo());
			ps.setInt(38, dto.getUpdateUserId());
			ps.setInt(39, dto.getCarScore());
			ps.setInt(40, dto.getRegisterStatus());
			ps.setInt(41, dto.getEntryStatus());
			ps.setInt(42, dto.getInsertUserId());
			ps.setString(43, dto.getPhoto_1());
			ps.setString(44, dto.getPhoto_2());
			ps.setString(45, dto.getPhoto_3());
			ps.setString(46, dto.getPhoto_4());
			ps.setString(47, dto.getPhoto_5());
			ps.setString(48, dto.getPhoto_6());
			ps.setString(49, dto.getPhoto_7());
			ps.setString(50, dto.getPhoto_8());
			ps.setInt(51, dto.getStatus());
			ps.setInt(52, dto.getAttestStatus());
			ps.executeUpdate();
			
			
		} catch (SQLException e) {
			logger.error("###########"+this.getClass()+"############## SQL异常 请查看详细信息");
			e.printStackTrace();
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
	
	public void saveMemberMarketCarInfo(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("INSERT INTO ");
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
			sql.append("(");
			sql.append(" CAROWNER, ");
			sql.append(" CARNAME, ");			
			sql.append(" SERIAL, ");
			sql.append(" VIN, ");
			sql.append(" ENGINE, ");
			sql.append(" LICENSEPLATE, ");
			sql.append(" PRICE, ");
			sql.append(" COLOR, ");
			sql.append(" MODELCODE, ");
			sql.append(" VENDORCODE, ");
			sql.append(" REGDATE, ");
			sql.append(" YEARCAREFULPERIOD, ");
			sql.append(" DISPLACEMENT, ");
			sql.append(" JQX, ");
			sql.append(" CARUSE, ");
			sql.append(" CARTYPE, ");
			sql.append(" MILEAGE, ");
			sql.append(" GEARBOX, ");
			sql.append(" SENDCARDDATE, ");
			sql.append(" CARDTYPE, ");
			sql.append(" COUNTRYSTYLE, ");
			sql.append(" REGISTERCARDNO, ");
			sql.append(" COMPANYCONTACTPERSON, ");
			sql.append(" COMPANYCONTACTPHONE, ");
			sql.append(" CAROWNERIDCARDNO, ");
			sql.append(" VENDORID, ");
			sql.append(" BRANDID, ");
			sql.append(" CARSTYLEID, ");
			sql.append(" MEMBERID, ");
			sql.append(" FUELTYPE, ");
			sql.append(" LOADQUALITY, ");
			sql.append(" PASSENGER, ");
			sql.append(" OWNERPHONE, ");
			sql.append(" OWNERADDRESS, ");
			sql.append(" ATTRIBUTE, ");
			sql.append(" OWNERTYPE, ");
			sql.append(" OWNERORGNO, ");
			sql.append(" INSERTTIME, ");
			sql.append(" UPDATETIME, ");
			sql.append(" UPDATEUSERID, ");
			sql.append(" CARSCORE,");
			sql.append(" REGISTERSTATUS,");
			sql.append(" ENTRYSTATUS,");
			sql.append(" INSERTUSERID,");
			sql.append(" PHOTO_1,");
			sql.append(" PHOTO_2,");
			sql.append(" PHOTO_3,");
			sql.append(" PHOTO_4,");
			sql.append(" PHOTO_5,");
			sql.append(" PHOTO_6,");
			sql.append(" PHOTO_7,");
			sql.append(" PHOTO_8,");
			sql.append(" STATUS,");
			sql.append("ATTESTSTATUS");
			sql.append("  ) VALUES ( ");
			sql.append(" ?,?,?,?,?,?,?,?,?,?" +
						",?,?,?,?,?,?,?,?,?,?" +
						",?,?,?,?,?,?,?,?,?,?" +
						",?,?,?,?,?,?,?,SYSDATE(),SYSDATE(),?" +
						",?,?,?,?,?,?,?,?,?,?,?,?,?,? )");

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, dto.getCarOwner());
			ps.setString(2, dto.getCarName());
			ps.setString(3, dto.getSerial());
			ps.setString(4, dto.getVin());
			ps.setString(5, dto.getEngine());
			ps.setString(6, dto.getLicensePlate());
			ps.setDouble(7, dto.getPrice());
			ps.setInt(8, dto.getColor());
			ps.setString(9, dto.getModelCode());
			ps.setString(10, dto.getVendorCode());
			ps.setString(11, dto.getRegDate());
			ps.setString(12, dto.getYearCarefulPeriod());
			ps.setInt(13, dto.getDisplacement());
			ps.setString(14, dto.getJqx());
			ps.setInt(15, dto.getCarUse());
			ps.setInt(16, dto.getCarType());
			ps.setDouble(17, dto.getMileage());
			ps.setInt(18, dto.getGearbox());
			ps.setString(19, dto.getSendCardDate());
			ps.setInt(20, dto.getCardType());
			ps.setInt(21, dto.getCountryStyle());
			ps.setString(22, dto.getRegisterCardNo());
			ps.setString(23, dto.getCompanyContactPerson());
			ps.setString(24, dto.getCompanyContactPhone());
			ps.setString(25, dto.getCarOwnerIdCardNo());
			ps.setString(26, dto.getVendorId());
			ps.setString(27, dto.getBrandId());
			ps.setString(28, dto.getCarStyleId());
			ps.setInt(29, dto.getMemberId());
			ps.setInt(30, dto.getFuelType());
			ps.setInt(31, dto.getLoadquality());
			ps.setInt(32, dto.getPassenger());
			ps.setString(33, dto.getOwnerPhone());
			ps.setString(34, dto.getOwnerAddress());
			ps.setInt(35, dto.getAttribute());
			ps.setInt(36, dto.getOwnerType());
			ps.setString(37, dto.getOwnerOrgNo());
			ps.setInt(38, dto.getUpdateUserId());
			ps.setInt(39, dto.getCarScore());
			ps.setInt(40, dto.getRegisterStatus());
			ps.setInt(41, dto.getEntryStatus());
			ps.setInt(42, dto.getInsertUserId());
			ps.setString(43, dto.getPhoto_1());
			ps.setString(44, dto.getPhoto_2());
			ps.setString(45, dto.getPhoto_3());
			ps.setString(46, dto.getPhoto_4());
			ps.setString(47, dto.getPhoto_5());
			ps.setString(48, dto.getPhoto_6());
			ps.setString(49, dto.getPhoto_7());
			ps.setString(50, dto.getPhoto_8());
			ps.setInt(51, dto.getStatus());
			ps.setInt(52, dto.getAttestStatus());
			ps.executeUpdate();
			
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
	
	@Override
	public void updateTroubleCarInfo(TroubleCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_TROUBLE_CAR_INFO);
		sql.append(" SET ");
		sql.append(" TROUBLETYPE=?,  ");
		sql.append(" REMARK=?,  ");
		sql.append(" INSERTTIME =SYSDATE() ");
		sql.append(" WHERE  ");
		sql.append(" VIN=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, dto.getTroubleType());
			ps.setString(2, dto.getRemark());
			ps.setString(3, dto.getVin());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}
	
	@Override
	public void deleteTroubleCarInfo(TroubleCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("");
			sql.append("DELETE ");
			sql.append("FROM ");
			sql.append(TmsTableNames.TMS_TROUBLE_CAR_INFO);
			sql.append(" WHERE ");
			sql.append(" VIN='"+dto.getVin()+"' ");
			ps = conn.prepareStatement(sql.toString());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			close(rs, ps);
		}		
	
	}
 
	public void insertTroubleCarInfo(TroubleCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("INSERT INTO ");
			sql.append(TmsTableNames.TMS_TROUBLE_CAR_INFO);
			sql.append("(");
			sql.append(" VIN, ");
			sql.append(" TROUBLETYPE, ");			
			sql.append(" REMARK, ");
			sql.append(" INSERTTIME ");
			sql.append("  ) VALUES ( ");
			sql.append(" ?,?,?,SYSDATE())");
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, dto.getVin());
			ps.setInt(2, dto.getTroubleType());
			ps.setString(3, dto.getRemark());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
	}
	
	
	public void insertPersonalCarInfo(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("INSERT INTO ");
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
			sql.append("(");
			sql.append(" CAROWNER, ");
			sql.append(" CARNAME, ");			
			sql.append(" SERIAL, ");
			sql.append(" VIN, ");
			sql.append(" ENGINE, ");
			sql.append(" LICENSEPLATE, ");
			sql.append(" PRICE, ");
			sql.append(" COLOR, ");
			sql.append(" MODELCODE, ");
			sql.append(" VENDORCODE, ");
			sql.append(" REGDATE, ");
			sql.append(" YEARCAREFULPERIOD, ");
			sql.append(" DISPLACEMENT, ");
			sql.append(" JQX, ");
			sql.append(" CARUSE, ");
			sql.append(" CARTYPE, ");
			sql.append(" MILEAGE, ");
			sql.append(" GEARBOX, ");
			sql.append(" SENDCARDDATE, ");
			sql.append(" CARDTYPE, ");
			sql.append(" COUNTRYSTYLE, ");
			sql.append(" REGISTERCARDNO, ");
			sql.append(" COMPANYCONTACTPERSON, ");
			sql.append(" COMPANYCONTACTPHONE, ");
			sql.append(" CAROWNERIDCARDNO, ");
			sql.append(" VENDORID, ");
			sql.append(" BRANDID, ");
			sql.append(" CARSTYLEID, ");
			sql.append(" MEMBERID, ");
			sql.append(" FUELTYPE, ");
			sql.append(" LOADQUALITY, ");
			sql.append(" PASSENGER, ");
			sql.append(" OWNERPHONE, ");
			sql.append(" OWNERADDRESS, ");
			sql.append(" ATTRIBUTE, ");
			sql.append(" OWNERTYPE, ");
			sql.append(" OWNERORGNO, ");
			sql.append(" INSERTTIME, ");
			sql.append(" UPDATETIME, ");
			sql.append(" UPDATEUSERID, ");
			sql.append(" CARSCORE,");
			sql.append(" REGISTERSTATUS,");
			sql.append(" ENTRYSTATUS,");
			sql.append(" INSERTUSERID,");
			sql.append(" PHOTO_1,");
			sql.append(" PHOTO_2,");
			sql.append(" PHOTO_3,");
			sql.append(" PHOTO_4,");
			sql.append(" PHOTO_5,");
			sql.append(" PHOTO_6,");
			sql.append(" PHOTO_7,");
			sql.append(" PHOTO_8,");
			sql.append(" STATUS,");
			sql.append("ENTERTIME,");
			sql.append("ATTESTSTATUS");
			sql.append("  ) VALUES ( ");
			sql.append(" ?,?,?,?,?,?,?,?,?,?" +
						",?,?,?,?,?,?,?,?,?,?" +
						",?,?,?,?,?,?,?,?,?,?" +
						",?,?,?,?,?,?,?,SYSDATE(),SYSDATE(),?" +
						",?,?,?,?,?,?,?,?,?,?,?,?,?,SYSDATE(),? )");

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, dto.getCarOwner());
			ps.setString(2, dto.getCarName());
			ps.setString(3, dto.getSerial());
			ps.setString(4, dto.getVin());
			ps.setString(5, dto.getEngine());
			ps.setString(6, dto.getLicensePlate());
			ps.setDouble(7, dto.getPrice());
			ps.setInt(8, dto.getColor());
			ps.setString(9, dto.getModelCode());
			ps.setString(10, dto.getVendorCode());
			ps.setString(11, dto.getRegDate());
			ps.setString(12, dto.getYearCarefulPeriod());
			ps.setInt(13, dto.getDisplacement());
			ps.setString(14, dto.getJqx());
			ps.setInt(15, dto.getCarUse());
			ps.setInt(16, dto.getCarType());
			ps.setDouble(17, dto.getMileage());
			ps.setInt(18, dto.getGearbox());
			ps.setString(19, dto.getSendCardDate());
			ps.setInt(20, dto.getCardType());
			ps.setInt(21, dto.getCountryStyle());
			ps.setString(22, dto.getRegisterCardNo());
			ps.setString(23, dto.getCompanyContactPerson());
			ps.setString(24, dto.getCompanyContactPhone());
			ps.setString(25, dto.getCarOwnerIdCardNo());
			ps.setString(26, dto.getVendorId());
			ps.setString(27, dto.getBrandId());
			ps.setString(28, dto.getCarStyleId());
			ps.setInt(29, dto.getMemberId());
			ps.setInt(30, dto.getFuelType());
			ps.setInt(31, dto.getLoadquality());
			ps.setInt(32, dto.getPassenger());
			ps.setString(33, dto.getOwnerPhone());
			ps.setString(34, dto.getOwnerAddress());
			ps.setInt(35, dto.getAttribute());
			ps.setInt(36, dto.getOwnerType());
			ps.setString(37, dto.getOwnerOrgNo());
			ps.setInt(38, dto.getUpdateUserId());
			ps.setInt(39, dto.getCarScore());
			ps.setInt(40, dto.getRegisterStatus());
			ps.setInt(41, dto.getEntryStatus());
			ps.setInt(42, dto.getInsertUserId());
			ps.setString(43, dto.getPhoto_1());
			ps.setString(44, dto.getPhoto_2());
			ps.setString(45, dto.getPhoto_3());
			ps.setString(46, dto.getPhoto_4());
			ps.setString(47, dto.getPhoto_5());
			ps.setString(48, dto.getPhoto_6());
			ps.setString(49, dto.getPhoto_7());
			ps.setString(50, dto.getPhoto_8());
			ps.setInt(51, dto.getStatus());
			ps.setInt(52, dto.getAttestStatus());
			ps.executeUpdate();
			
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
	/**
	 * 高级搜索
	 * @throws TmsDaoException 
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List findSeniorSearchResultByCon(String carClass, String vendorId,
			String brandId, String licensePlant, String vin, String memId,
			String startTime, String endTime,String registerStatus,String barCodeNum,
		    String tempLicensePlate,String minPrice,String maxPrice,String startYear,String endYear) throws TmsDaoException {
		// 开始掉数据
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> list = new ArrayList<MarketCarInfoDto>();
		/**
		 *  车辆
			车辆名称
			车牌号码
			VIN码
			商家名称
			库存状态
			挂起状态
			入库时间
	        vendorCode = ""; // 车辆厂牌代码 【此数据在检测中心填写，根据行驶证上内容记录】
	        modelCode = ""; // 车辆型号代码 【此数据在检测中心填写，根据行驶证上内容记录】
		 */
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append("MARKET.SERIAL AS SERIAL, ");
		sql.append("MARKET.CARNAME AS CARNAME, ");//车辆名称
		sql.append("MARKET.LICENSEPLATE AS LICENSEPLATE, ");//车牌号
		sql.append("MARKET.VIN AS VIN, ");//车架号
		sql.append("MARKET.REGISTERSTATUS AS REGISTERSTATUS,");//库存状态
		sql.append("MARKET.BARCODENUM AS BARCODENUM,");//挂起状态
		sql.append("MEMBER.SHORTNAME  AS SHORTNAME,");//商户名称
		sql.append("MARKET.INSERTTIME AS INSERTTIME,  ");//登记日期
		sql.append("MARKET.STATUS AS STATUS  ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" AS MARKET  ");
		sql.append(" LEFT JOIN  ");//和member表关联
		sql.append(TmsTableNames.TMS_MEMBER);
		sql.append(" AS MEMBER  ");
		sql.append(" ON MEMBER.MEMBERID = MARKET.MEMBERID  ");
		sql.append(" WHERE ");
		//开始判断
		/**
		 * 1.车辆号码查询----
		 * 2.车牌号码查询----
		 * 3.VIN码查询--
		 * 4.商家名称需要与tms_member表关联---
		 * 5.入库时间和update时间进行比对
		 * 
		 */
		
		if(registerStatus!=null&&!StringUtil.isNullOrBlank(registerStatus)){
			sql.append(" MARKET.REGISTERSTATUS = '"+registerStatus+"'" );//库存状态
		}else {
			sql.append(" MARKET.REGISTERSTATUS <> 4 ");
		}
		//
        if(StringUtil.isNotBlank(tempLicensePlate)){
        	sql.append(" AND MARKET.TEMPLICENSEPLATE LIKE '%"+tempLicensePlate+"' ");
		}
        if(StringUtil.isNotBlank(minPrice) && StringUtil.isNotBlank(maxPrice)){
        	sql.append(" AND MARKET.PRICE >='" + minPrice+"'" +" AND MARKET.PRICE <='"+maxPrice+"'");
		}
        if(StringUtil.isNotBlank(startYear) && StringUtil.isNotBlank(endYear)){
        	sql.append(" AND MARKET.REGDATE <> '' AND TIMESTAMPDIFF(YEAR,REGDATE,NOW()) >= '"+startYear+"' AND TIMESTAMPDIFF(YEAR,REGDATE,NOW())<='"+endYear+"'");
        }else if(StringUtil.isNotBlank(startYear) || StringUtil.isNotBlank(endYear)){
        	sql.append(" AND MARKET.REGDATE <> '' AND TIMESTAMPDIFF(YEAR,REGDATE,NOW())  = '"+startYear+"'");
        }
        //
		if(memId!=null&&!"".equals(memId))
		{
			sql.append(" AND MARKET.MEMBERID= '"+memId+"' ");//会员判断
		}
		if(vin!=null&&!"".equals(vin))
		{
			sql.append(" AND MARKET.VIN LIKE '%"+vin+"' ");//车辆识别码
		}
		if(licensePlant!=null&&!"".equals(licensePlant))
		{
			sql.append(" AND MARKET.LICENSEPLATE LIKE '%"+licensePlant+"' ");//车牌号
		}
		if(startTime!=null&&!"".equals(startTime))
		{
			sql.append(" AND DATE_FORMAT(MARKET.INSERTTIME,'%Y-%m-%d') >=  '"+startTime+"'");//开始时间
		}
		if(endTime!=null&&!"".equals(endTime))
		{
			sql.append(" AND DATE_FORMAT(MARKET.INSERTTIME,'%Y-%m-%d') <=  '"+endTime+"'");//结束时间
		}
		if(!StringUtil.isNullOrBlank(carClass)){
			sql.append(" AND MARKET.CATCLASS = '"+carClass+"' ");//车辆种类
		}
		if(!StringUtil.isNullOrBlank(vendorId)){
			sql.append(" AND MARKET.VENDORID = '"+vendorId+"' ");//车辆品牌
		}
		if(brandId!=null&&!"".equals(brandId)){	
			sql.append(" AND MARKET.BRANDID = '"+brandId+"'" );//车系
		}
		if(barCodeNum!=null&&!StringUtil.isNullOrBlank(barCodeNum)){
			sql.append(" AND MARKET.BARCODENUM =  '"+barCodeNum+"'" );//挂起状态
		}
		sql.append(" ORDER BY INSERTTIME ASC");

		MarketCarInfoDto carDto = null;
		try {

			ps = conn.prepareStatement(getSql(sql.toString()));
			rs = ps.executeQuery();
			int i=0;
			while (rs.next()) {
				carDto = new MarketCarInfoDto();
				carDto.setSerial(rs.getString("SERIAL"));
				carDto.setBrandName(rs.getString("CARNAME"));				
				carDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				carDto.setVin(rs.getString("VIN"));
				carDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				carDto.setBarCodeNum(rs.getInt("BARCODENUM"));
				carDto.setMemberName(rs.getString("SHORTNAME"));				
				carDto.setSearchInTime(DateUtil.getTimeByTimeStamp1(rs.getTimestamp("INSERTTIME")));
				carDto.setStatus(rs.getInt("STATUS"));
				
				if(i%2 == 0){
					carDto.setCssFlag(1);
				}else{
					carDto.setCssFlag(2);
				}
				int num = (i+1)+(getPageNo()-1)*50;
				carDto.setNum(num);
				list.add(carDto);
				i++;
			}
			
			return list;

		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}		
	}

	@Override
	public List findImCarName(String startTime, String endTime,int type,int carRidio)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		List sperialCarList = new ArrayList();
		StringBuffer sql = new StringBuffer("");
		if(type == 3){
			sql.append("SELECT BASICCARID,SERIAL,LICENSEPLATE,VIN,MODELCODE,VENDORCODE, ");
		}else{
			sql.append("SELECT SERIAL,LICENSEPLATE,VIN,MODELCODE,VENDORCODE, ");
		}
	
		if(type == 3){
			sql.append("ACCPETTIME FROM ");
		}else{
			sql.append("INSERTTIME FROM ");
		}
		if(type == 1){		
			sql.append(TmsTableNames.TMS_TRANSFER_PERSONALCAR_INFO );
		}else if(type == 2){
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO );
		}else if(type == 3){
			sql.append(TmsTableNames.TMS_MARKET_CAR_TRANS_INFO );
		}
        sql.append(" WHERE ");	
        if(carRidio == 2){
        	sql.append("CARSTYLEID IS NOT NULL AND CARSTYLEID<>''");
        }else{
        	sql.append("LENGTH(VIN) = 17 AND ");
    		sql.append(" VIN IS NOT NULL AND VIN <> ''");
    		sql.append(" AND ");
    		sql.append(" (CARSTYLEID IS NULL OR CARSTYLEID='')");
        }
        
		if(type == 3){
			sql.append(" AND DATE_FORMAT(ACCPETTIME,'%Y-%m-%d')>='"+ startTime +"' AND DATE_FORMAT(ACCPETTIME,'%Y-%m-%d')<'"+endTime+"'");
		}else{
			sql.append(" AND DATE_FORMAT(INSERTTIME,'%Y-%m-%d')>='"+ startTime +"' AND DATE_FORMAT(INSERTTIME,'%Y-%m-%d')<'"+endTime+"'");
		}
		if(type == 3){
			sql.append(getOrderBySql(spericalCarOldList));
		}else{
			sql.append(getOrderBySql(spericalCarList));
		}
		
		try {
			ps = conn.prepareStatement(getSql(sql.toString()));
			rs = ps.executeQuery();
			int i=0;
			MarketCarInfoDto carDto = null;
			while(rs.next()){
				carDto = new MarketCarInfoDto();
				if(type == 3){
					carDto.setSerial(rs.getString("BASICCARID"));
					carDto.setTransferSerial(rs.getString("SERIAL"));
				}else{
					carDto.setSerial(rs.getString("SERIAL"));
				}
				
				carDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				carDto.setVin(rs.getString("VIN"));
				carDto.setModelCode(rs.getString("MODELCODE"));
				carDto.setVendorCode(rs.getString("VENDORCODE"));
				if(type == 3){
					carDto.setInsertTime(rs.getTimestamp("ACCPETTIME"));
				}else{
					carDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				}
				
				int num = (i+1)+(getPageNo()-1)*30;
				carDto.setNum(num);
				sperialCarList.add(carDto);
				i++;
			}
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}	
		
		
		
		
		return sperialCarList;
	}	
	
	
	@SuppressWarnings("unchecked")
	public List<MarketCarGateInfoDto> findInoutResult(String serial, String threadStatus,
			String gateId, String startTime, String endTime)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarGateInfoDto> list = new ArrayList<MarketCarGateInfoDto>();
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append("GATEINFO.THREADTYPE AS THREADTYPE, ");
		sql.append("GATEINFO.GATETYPE AS GATETYPE, ");
		sql.append("GATEINFO.CARPHOTO AS CARPHOTO, ");
		sql.append("GATEINFO.CHECKFLAG AS CHECKFLAG, ");
		sql.append("GATEINFO.LOCATEDIP AS LOCATEDIP, ");
		sql.append("GATEINFO.THREADSTATUS AS THREADSTATUS, ");
		sql.append("GATEINFO.SERIAL AS SERIAL, ");
		sql.append("GATEINFO.LICENSEPLATE AS LICENSEPLATE, ");
		sql.append("MEMBER.SHORTNAME  AS SHORTNAME,");
		sql.append("GATEINFO.GATEID  AS GATEID,");
		sql.append("GATEINFO.COLOR  AS COLOR,");
		sql.append("GATEINFO.LICENSECOLOR  AS LICENSECOLOR,");
		sql.append("GATEINFO.INSERTTIME  AS INSERTTIME");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_GATEINFO);
		sql.append(" AS GATEINFO  ");		
		sql.append(" LEFT JOIN  ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" AS MARKET  ");
		sql.append(" ON GATEINFO.SERIAL = MARKET.SERIAL  ");
		sql.append(" LEFT JOIN  ");//和member表关联
		sql.append(TmsTableNames.TMS_MEMBER);
		sql.append(" AS MEMBER  ");
		sql.append(" ON MEMBER.MEMBERID = MARKET.MEMBERID  ");
		sql.append(" WHERE 1=1");
		if(!StringUtil.isNullOrBlank(serial)){
			sql.append(" AND GATEINFO.SERIAL=  '"+serial+"'");//车辆编码
		}
		if(!StringUtil.isNullOrBlank(threadStatus)){
			sql.append(" AND GATEINFO.THREADSTATUS= '"+threadStatus+"'");//会员判断			
		}
		if(!StringUtil.isNullOrBlank(gateId)){
			sql.append(" AND GATEINFO.GATEID%2 = '"+Integer.valueOf(gateId)%2+"'");
		}
		if(startTime!=null&&!"".equals(startTime))
		{
			sql.append(" AND DATE_FORMAT(GATEINFO.INSERTTIME,'%Y-%m-%d') >=  '"+startTime+"'");//开始时间
		}
		if(endTime!=null&&!"".equals(endTime))
		{
			sql.append(" AND DATE_FORMAT(GATEINFO.INSERTTIME,'%Y-%m-%d') <=  '"+endTime+"'");//结束时间
		}
		sql.append(getOrderBySql(inoutSortKeyList));
		
		MarketCarGateInfoDto carDto = null;
		try {
			ps = conn.prepareStatement(getSql(sql.toString()));
			rs = ps.executeQuery();
			int i=0;
			while (rs.next()){
				carDto = new MarketCarGateInfoDto();
				carDto.setSerial(rs.getString("SERIAL"));
				carDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				carDto.setMemberName(rs.getString("SHORTNAME"));	
				carDto.setCarColor(rs.getInt("COLOR"));
				carDto.setLicenseColor(rs.getInt("LICENSECOLOR"));
				carDto.setLocatedIP(rs.getString("LOCATEDIP"));
				carDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				carDto.setThreadType(rs.getInt("THREADTYPE"));
				carDto.setGateType(rs.getString("GATETYPE"));
				carDto.setCarPhoto(rs.getString("CARPHOTO"));
				carDto.setThreadStatus(rs.getInt("THREADSTATUS"));
				carDto.setCheckFlag(rs.getInt("CHECKFLAG"));
				if(i%2 == 0){
					carDto.setCssFlag(1);
				}else{
					carDto.setCssFlag(2);
				}
				int num = (i+1)+(getPageNo()-1)*30;
				carDto.setNum(num);
				list.add(carDto);
				i++;
			}
			return list;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}	
	}
	
	@Override
	public MarketCarInfoDto findCarByLicensePlate(String licensePlate)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = new MarketCarInfoDto();
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT SERIAL,");
		sql.append("ID,");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("LICENSEPLATE,");
		sql.append("PRICE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("MEMBERID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("ATTRIBUTE,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("UPDATETIME,");
		sql.append("UPDATEUSERID,");
		sql.append("PHOTO_1, ");
		sql.append("PHOTO_2, ");
		sql.append("PHOTO_3, ");
		sql.append("PHOTO_4, ");
		sql.append("PHOTO_5, ");
		sql.append("PHOTO_6, ");
		sql.append("PHOTO_7, ");
		sql.append("PHOTO_8, ");
		sql.append("IMAGEPATH, ");
		sql.append("REGISTERSTATUS, ");
		sql.append("ENTRYSTATUS, ");	
		sql.append("INSERTUSERID, ");
		sql.append("VENDORID ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" LICENSEPLATE=?");
		sql.append(" ORDER BY ID DESC");
		
		
		try {

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, licensePlate);			
			rs = ps.executeQuery();
			int i =1;
			
			while (rs.next()) {
				if(i==2){
					break;
				}
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setImagePath(rs.getString("IMAGEPATH"));
				i++;
			}
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}

	
	
	@Override
	public MarketCarInfoDto findCarByNewLicensePlate(String licensePlate) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT SERIAL,");
		sql.append("ID,");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("LICENSEPLATE,");
		sql.append("PRICE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("MEMBERID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("ATTRIBUTE,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("UPDATETIME,");
		sql.append("UPDATEUSERID,");
		sql.append("PHOTO_1, ");
		sql.append("PHOTO_2, ");
		sql.append("PHOTO_3, ");
		sql.append("PHOTO_4, ");
		sql.append("PHOTO_5, ");
		sql.append("PHOTO_6, ");
		sql.append("PHOTO_7, ");
		sql.append("PHOTO_8, ");
		sql.append("IMAGEPATH, ");
		sql.append("REGISTERSTATUS, ");
		sql.append("ENTRYSTATUS, ");	
		sql.append("INSERTUSERID, ");
		sql.append("VENDORID, ");
		sql.append("BARCODENUM, ");
		sql.append("TMPSTORAGETIME, ");
		sql.append("TMPENTERTIME, ");
		sql.append("TMPSTORAGETIME, ");
		sql.append("TMPENTERTIME, ");
		sql.append("ENTERTIME ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" (NEWLICENSEPLATE LIKE ? OR NEWLICENSEPLATE LIKE ?)");
//		sql.append(" AND REGISTERSTATUS not in (3,4) " );
		sql.append(" AND TIMESTAMPDIFF( DAY, DATE_FORMAT(CHGLICENSEPLATETIME,'%Y-%m-%d'),DATE_FORMAT(CURDATE(),'%Y-%m-%d')) <15 " );
		sql.append(" ORDER BY UPDATETIME DESC");
		sql.append(" LIMIT 1");
		try {
			ps = conn.prepareStatement(sql.toString());
			String param1 = licensePlate.substring(2);
			String param2 = licensePlate.substring(1);
			ps.setString(1, "%"+param1);
			ps.setString(2, "%"+param2);
			rs = ps.executeQuery();
			while (rs.next()) { 
				marketCarInfoDto = new MarketCarInfoDto(); 
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setImagePath(rs.getString("IMAGEPATH"));
				marketCarInfoDto.setBarCodeNum(rs.getInt("BARCODENUM"));
				marketCarInfoDto.setTmpStorageTime(rs.getTimestamp("TMPSTORAGETIME"));
				marketCarInfoDto.setTmpEnterTime(rs.getTimestamp("TMPENTERTIME"));
				marketCarInfoDto.setTmpStorageTime(rs.getTimestamp("TMPSTORAGETIME"));
				marketCarInfoDto.setTmpEnterTime(rs.getTimestamp("TMPENTERTIME"));
				marketCarInfoDto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				break;
			}
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}


	
	
	
	@Override
	public MarketCarInfoDto findPrivilegeCarByLicensePlate(String id,int type) throws TmsDaoException {
		if(StringUtil.isNullOrBlank(id)) return null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ID,");
		sql.append("TEMPLICENSEPLATE,");
		sql.append("LICENSEPLATE,");
		sql.append("ENTERTIME,");
		sql.append("REGISTERSTATUS,");
		sql.append("REMARK,");
		sql.append("UPDATETIME,");
		sql.append("UPDATEUSERID ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_PRIVILEGE);
		sql.append(" WHERE " );
		if(type == PlateNumberTypes.TEMP_PLATE_NUMBER.getValue()) sql.append(" (TEMPLICENSEPLATE LIKE ?)");
		else sql.append(" (LICENSEPLATE LIKE ? OR LICENSEPLATE LIKE ?)");
		sql.append(" AND REGISTERSTATUS = 1 " );
		sql.append(" ORDER BY UPDATETIME DESC");
		sql.append(" LIMIT 1");
		try {
			ps = conn.prepareStatement(sql.toString());
			if(type == PlateNumberTypes.TEMP_PLATE_NUMBER.getValue()) {
				ps.setString(1, "%"+id);
			}else {
				String param1 = id.substring(2);
				String param2 = id.substring(1);
				ps.setString(1, "%"+param1);
				ps.setString(2, "%"+param2);
			}
			rs = ps.executeQuery();
			while (rs.next()) { 
				marketCarInfoDto = new MarketCarInfoDto(); 
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setTempLicensePlate(rs.getString("TEMPLICENSEPLATE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setRemark(rs.getString("REMARK"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				break;
			}
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}


	@Override
	public MarketCarInfoDto findCarByTempLicensePlate(String licensePlate,int beginIndex) throws TmsDaoException {
		//
		String param = licensePlate.substring(beginIndex);
		//
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT SERIAL,");
		sql.append("ID,");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("LICENSEPLATE,");
		sql.append("PRICE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("MEMBERID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("ATTRIBUTE,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("UPDATETIME,");
		sql.append("UPDATEUSERID,");
		sql.append("PHOTO_1, ");
		sql.append("PHOTO_2, ");
		sql.append("PHOTO_3, ");
		sql.append("PHOTO_4, ");
		sql.append("PHOTO_5, ");
		sql.append("PHOTO_6, ");
		sql.append("PHOTO_7, ");
		sql.append("PHOTO_8, ");
		sql.append("IMAGEPATH, ");
		sql.append("REGISTERSTATUS, ");
		sql.append("ENTRYSTATUS, ");	
		sql.append("INSERTUSERID, ");
		sql.append("VENDORID, ");
		sql.append("BARCODENUM, ");
		sql.append("TMPSTORAGETIME, ");
		sql.append("TMPENTERTIME, ");
		sql.append("TMPSTORAGETIME, ");
		sql.append("INSERTTIME, ");
		sql.append("TMPENTERTIME, ");
		sql.append("ENTERTIME ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" TEMPLICENSEPLATE LIKE ?");
//		sql.append(" AND REGISTERSTATUS not in (3,4) " );
		sql.append(" ORDER BY UPDATETIME DESC");
		sql.append(" LIMIT 1");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, "%"+param);			
			rs = ps.executeQuery();
			while (rs.next()) { 
				marketCarInfoDto = new MarketCarInfoDto(); 
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setImagePath(rs.getString("IMAGEPATH"));
				marketCarInfoDto.setBarCodeNum(rs.getInt("BARCODENUM"));
				marketCarInfoDto.setTmpStorageTime(rs.getTimestamp("TMPSTORAGETIME"));
				marketCarInfoDto.setTmpEnterTime(rs.getTimestamp("TMPENTERTIME"));
				marketCarInfoDto.setTmpStorageTime(rs.getTimestamp("TMPSTORAGETIME"));
				marketCarInfoDto.setTmpEnterTime(rs.getTimestamp("TMPENTERTIME"));
				marketCarInfoDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				marketCarInfoDto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				break;
			}
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}


	@Override
	public MarketCarInfoDto findCarByLicensePlateInventory(String licensePlate) throws TmsDaoException {
		//
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT SERIAL,");
		sql.append("ID,");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("LICENSEPLATE,");
		sql.append("PRICE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("MEMBERID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("ATTRIBUTE,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("UPDATETIME,");
		sql.append("UPDATEUSERID,");
		sql.append("PHOTO_1, ");
		sql.append("PHOTO_2, ");
		sql.append("PHOTO_3, ");
		sql.append("PHOTO_4, ");
		sql.append("PHOTO_5, ");
		sql.append("PHOTO_6, ");
		sql.append("PHOTO_7, ");
		sql.append("PHOTO_8, ");
		sql.append("IMAGEPATH, ");
		sql.append("REGISTERSTATUS, ");
		sql.append("ENTRYSTATUS, ");	
		sql.append("INSERTUSERID, ");
		sql.append("VENDORID, ");
		sql.append("STATUS, ");
		sql.append("BARCODENUM, ");
        sql.append("INSERTTIME, ");
        sql.append("TMPSTORAGETIME, ");
		sql.append("TMPENTERTIME, ");
		sql.append("ENTERTIME ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" (LICENSEPLATE like ? OR LICENSEPLATE like ? )");
//		sql.append(" AND REGISTERSTATUS not in (3,4) " );
		sql.append(" ORDER BY UPDATETIME DESC");
		sql.append(" LIMIT 1");
		try {
			//
			String param1 = licensePlate.substring(2);
			String param2 = licensePlate.substring(1);
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, "%"+param1);
			ps.setString(2, "%"+param2);
			rs = ps.executeQuery();
			while (rs.next()) { 
				marketCarInfoDto = new MarketCarInfoDto(); 
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setImagePath(rs.getString("IMAGEPATH"));
				marketCarInfoDto.setBarCodeNum(rs.getInt("BARCODENUM"));
				marketCarInfoDto.setStatus(rs.getInt("STATUS"));
				marketCarInfoDto.setTmpStorageTime(rs.getTimestamp("TMPSTORAGETIME"));
				marketCarInfoDto.setTmpEnterTime(rs.getTimestamp("TMPENTERTIME"));
				marketCarInfoDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				marketCarInfoDto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				break;
			}
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}

	//WL:20150509
	@Override
	public void updateMarketCarInfo(MarketCarInfoDto marketCarInfoDto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getCarOwner())) sql.append(" CAROWNER=?,");
		if(!StringUtil.isNullOrBlank( marketCarInfoDto.getCarName())) sql.append(" CARNAME=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getVin())) sql.append(" VIN=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getEngine())) sql.append(" ENGINE=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getLicensePlate())) sql.append(" LICENSEPLATE=?,");
		if(marketCarInfoDto.getPrice()!=0) sql.append(" PRICE=?,");
		if(marketCarInfoDto.getColor()!=0) sql.append(" COLOR=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getModelCode())) sql.append(" MODELCODE=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getVendorCode())) sql.append(" VENDORCODE=?,");
		if(!StringUtil.isNullOrBlank( marketCarInfoDto.getRegDate())) sql.append(" REGDATE=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getYearCarefulPeriod())) sql.append(" YEARCAREFULPERIOD=?,");
		if( marketCarInfoDto.getDisplacement()!=0) sql.append(" DISPLACEMENT=?,");
		if(!StringUtil.isNullOrBlank( marketCarInfoDto.getJqx())) sql.append(" JQX=?,");
		if(marketCarInfoDto.getCarUse()!=0) sql.append(" CARUSE=?,");
		if(marketCarInfoDto.getCarType()!=0) sql.append(" CARTYPE=?,");
		if(marketCarInfoDto.getMileage()!=0) sql.append(" MILEAGE=?,");
		if(marketCarInfoDto.getGearbox()!=0) sql.append(" GEARBOX=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getSendCardDate())) sql.append(" SENDCARDDATE=?,");
		if(marketCarInfoDto.getCardType()!=0) sql.append(" CARDTYPE=?,");
		if(marketCarInfoDto.getCountryStyle()!=0) sql.append(" COUNTRYSTYLE=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getRegisterCardNo())) sql.append(" REGISTERCARDNO=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getCompanyContactPerson()))sql.append(" COMPANYCONTACTPERSON=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getCompanyContactPhone())) sql.append(" COMPANYCONTACTPHONE=?,");
		if(!StringUtil.isNullOrBlank( marketCarInfoDto.getCarOwnerIdCardNo())) sql.append(" CAROWNERIDCARDNO=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getCarStyleId())) sql.append(" CARSTYLEID=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getBrandId())) sql.append(" BRANDID=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getVendorId())) sql.append(" VENDORID=?,");
		if(marketCarInfoDto.getMemberId()!=0) sql.append(" MEMBERID=?,");
		if(marketCarInfoDto.getFuelType()!=0) sql.append(" FUELTYPE=?,");
		if(marketCarInfoDto.getLoadquality()!=0) sql.append(" LOADQUALITY=?,");
		if(marketCarInfoDto.getPassenger()!=0) sql.append(" PASSENGER=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getOwnerPhone())) sql.append(" OWNERPHONE=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getOwnerAddress())) sql.append(" OWNERADDRESS=?,");
		if(marketCarInfoDto.getAttribute()!=0)sql.append(" ATTRIBUTE=?,");
		if(marketCarInfoDto.getOwnerType()!=-1) sql.append(" OWNERTYPE=?,");
		if(!StringUtil.isNullOrBlank(marketCarInfoDto.getOwnerOrgNo())) sql.append(" OWNERORGNO=?,");		
        sql.append(" UPDATETIME=SYSDATE(),");
        if(marketCarInfoDto.getUpdateUserId()!=0) sql.append(" UPDATEUSERID=?, ");
        if(marketCarInfoDto.getInsertUserId()!=0) sql.append(" INSERTUSERID=?, ");
        if(marketCarInfoDto.getRegisterStatus()!=0) sql.append(" REGISTERSTATUS=?,");
        if(marketCarInfoDto.getEntryStatus()!=-1) sql.append(" ENTRYSTATUS=?," );
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_1())) sql.append(" PHOTO_1=?," );
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_2())) sql.append(" PHOTO_2=?," );
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_3())) sql.append(" PHOTO_3=?," );
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_4())) sql.append(" PHOTO_4=?," );
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_5())) sql.append(" PHOTO_5=?," );
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_6())) sql.append(" PHOTO_6=?," );
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_7())) sql.append(" PHOTO_7=?," );
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_8())) sql.append(" PHOTO_8=?," );
        if(marketCarInfoDto.getStatus()!=0) sql.append(" STATUS=?,");
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getRemark())) sql.append(" REMARK=?,");
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getTempLicensePlate())) sql.append(" tempLicensePlate=?,");
        if(marketCarInfoDto.getIsMatch()==2) sql.append(" ISMATCH=2,"); // add by mufeiyu
        if(marketCarInfoDto.getCatClass()!=0) sql.append(" CATCLASS=?,"); // add by mufeiyu;
        if(!StringUtil.isNullOrBlank(marketCarInfoDto.getConfigKey())) sql.append(" CONFIGKEY=?,"); // add by mufeiyu;
        if(marketCarInfoDto.isInsertTimeUpadateFlg()) sql.append("  INSERTTIME=SYSDATE(),"); // add by mufeiyu;
        if(marketCarInfoDto.getAttestStatus()!=0) sql.append(" ATTESTSTATUS=?,  ");
     	if(marketCarInfoDto.getIsShelve()!=0) sql.append(" isShelve=? ");
		
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			
			ps = conn.prepareStatement(sql.toString());
			int i = 0;
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getCarOwner())) ps.setString(++i, marketCarInfoDto.getCarOwner());
			if(!StringUtil.isNullOrBlank( marketCarInfoDto.getCarName())) ps.setString(++i, marketCarInfoDto.getCarName());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getVin())) ps.setString(++i, marketCarInfoDto.getVin());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getEngine())) ps.setString(++i, marketCarInfoDto.getEngine());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getLicensePlate())) ps.setString(++i, marketCarInfoDto.getLicensePlate());
			if(marketCarInfoDto.getPrice()!=0) ps.setDouble(++i, marketCarInfoDto.getPrice());
			if(marketCarInfoDto.getColor()!=0) ps.setInt(++i, marketCarInfoDto.getColor());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getModelCode())) ps.setString(++i, marketCarInfoDto.getModelCode());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getVendorCode())) ps.setString(++i, marketCarInfoDto.getVendorCode());
			if(!StringUtil.isNullOrBlank( marketCarInfoDto.getRegDate())) ps.setString(++i, marketCarInfoDto.getRegDate());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getYearCarefulPeriod())) ps.setString(++i, marketCarInfoDto.getYearCarefulPeriod());
			if( marketCarInfoDto.getDisplacement()!=0) ps.setInt(++i, marketCarInfoDto.getDisplacement());
			if(!StringUtil.isNullOrBlank( marketCarInfoDto.getJqx())) ps.setString(++i, marketCarInfoDto.getJqx());
			if(marketCarInfoDto.getCarUse()!=0) ps.setInt(++i, marketCarInfoDto.getCarUse());
			if(marketCarInfoDto.getCarType()!=0) ps.setInt(++i, marketCarInfoDto.getCarType());
			if(marketCarInfoDto.getMileage()!=0) ps.setDouble(++i, marketCarInfoDto.getMileage());
			if(marketCarInfoDto.getGearbox()!=0) ps.setLong(++i, marketCarInfoDto.getGearbox());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getSendCardDate())) ps.setString(++i, marketCarInfoDto.getSendCardDate());
			if(marketCarInfoDto.getCardType()!=0) ps.setInt(++i, marketCarInfoDto.getCardType());
			if(marketCarInfoDto.getCountryStyle()!=0) ps.setInt(++i, marketCarInfoDto.getCountryStyle());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getRegisterCardNo())) ps.setString(++i, marketCarInfoDto.getRegisterCardNo());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getCompanyContactPerson())) ps.setString(++i, marketCarInfoDto.getCompanyContactPerson());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getCompanyContactPhone())) ps.setString(++i, marketCarInfoDto.getCompanyContactPhone());
			if(!StringUtil.isNullOrBlank( marketCarInfoDto.getCarOwnerIdCardNo())) ps.setString(++i, marketCarInfoDto.getCarOwnerIdCardNo());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getCarStyleId())) ps.setString(++i, marketCarInfoDto.getCarStyleId());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getBrandId())) ps.setString(++i, marketCarInfoDto.getBrandId());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getVendorId())) ps.setString(++i, marketCarInfoDto.getVendorId());
			if(marketCarInfoDto.getMemberId()!=0) ps.setInt(++i, marketCarInfoDto.getMemberId());
			if(marketCarInfoDto.getFuelType()!=0) ps.setLong(++i, marketCarInfoDto.getFuelType());
			if(marketCarInfoDto.getLoadquality()!=0) ps.setInt(++i, marketCarInfoDto.getLoadquality());
			if(marketCarInfoDto.getPassenger()!=0) ps.setInt(++i, marketCarInfoDto.getPassenger());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getOwnerPhone())) ps.setString(++i, marketCarInfoDto.getOwnerPhone());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getOwnerAddress())) ps.setString(++i, marketCarInfoDto.getOwnerAddress());
			if(marketCarInfoDto.getAttribute()!=0) ps.setLong(++i, marketCarInfoDto.getAttribute());
			if(marketCarInfoDto.getOwnerType()!=-1) ps.setInt(++i, marketCarInfoDto.getOwnerType());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getOwnerOrgNo())) ps.setString(++i, marketCarInfoDto.getOwnerOrgNo());		
			if(marketCarInfoDto.getUpdateUserId()!=0) ps.setInt(++i, marketCarInfoDto.getUpdateUserId());
			if(marketCarInfoDto.getInsertUserId()!=0) ps.setInt(++i, marketCarInfoDto.getInsertUserId());
			if(marketCarInfoDto.getRegisterStatus()!=0) ps.setInt(++i, marketCarInfoDto.getRegisterStatus());
			if(marketCarInfoDto.getEntryStatus()!=-0) ps.setInt(++i, marketCarInfoDto.getEntryStatus());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_1())) ps.setString(++i, marketCarInfoDto.getPhoto_1());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_2())) ps.setString(++i, marketCarInfoDto.getPhoto_2());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_3())) ps.setString(++i, marketCarInfoDto.getPhoto_3());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_4())) ps.setString(++i, marketCarInfoDto.getPhoto_4());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_5())) ps.setString(++i, marketCarInfoDto.getPhoto_5());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_6())) ps.setString(++i, marketCarInfoDto.getPhoto_6());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_7())) ps.setString(++i, marketCarInfoDto.getPhoto_7());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getPhoto_8())) ps.setString(++i, marketCarInfoDto.getPhoto_8());
			if(marketCarInfoDto.getStatus()!=0) ps.setInt(++i, marketCarInfoDto.getStatus());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getRemark())) ps.setString(++i, marketCarInfoDto.getRemark());
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getTempLicensePlate())) ps.setString(++i, marketCarInfoDto.getTempLicensePlate());
			if(marketCarInfoDto.getCatClass()!=0) ps.setInt(++i, marketCarInfoDto.getCatClass()); // add by mufeiyu;
			if(!StringUtil.isNullOrBlank(marketCarInfoDto.getConfigKey())) ps.setString(++i, marketCarInfoDto.getConfigKey()); // add by mufeiyu;
			if(marketCarInfoDto.getAttestStatus()!=0) ps.setInt(++i, marketCarInfoDto.getAttestStatus());
			if(marketCarInfoDto.getIsShelve()!=0) ps.setInt(++i, marketCarInfoDto.getIsShelve());
			ps.setString(++i, marketCarInfoDto.getSerial());
			logger.error("入参:"+marketCarInfoDto);
			logger.error("@quwei执行SQL:"+sql);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
		

		
	}


	@Override
	public MarketCarInfoDto findCarBySerial(String serial)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT SERIAL,");
		sql.append("ID,");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("TEMPLICENSEPLATE,");
		sql.append("LICENSEPLATE,");
		sql.append("PRICE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("MEMBERID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("ATTRIBUTE,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("UPDATETIME,");
		sql.append("UPDATEUSERID, ");
		sql.append("PHOTO_1, ");
		sql.append("PHOTO_2, ");
		sql.append("PHOTO_3, ");
		sql.append("PHOTO_4, ");
		sql.append("PHOTO_5, ");
		sql.append("PHOTO_6, ");
		sql.append("PHOTO_7, ");
		sql.append("PHOTO_8, ");
		sql.append("REGISTERSTATUS, ");
		sql.append("ENTRYSTATUS, ");	
		sql.append("INSERTUSERID, ");
		sql.append("VENDORID, ");
		sql.append("STATUS, ");
		sql.append("CARSCORE, ");
		sql.append("ATTESTSTATUS, ");
		sql.append("STORAGETIME, ");
		sql.append("ENTERTIME, ");
		sql.append("NEWLICENSEPLATE, ");
		sql.append("CHGLICENSEPLATETIME, ");
		sql.append("CARNAME, ");
		sql.append("INSERTTIME, ");
		sql.append("INSERTUSERID, ");
		sql.append("BARCODENUM, ");
		sql.append("REMARK, ");
		sql.append("ISMATCH, ");
		sql.append("ISSHELVE, ");
		sql.append("TMPSTORAGETIME, ");
		sql.append("TMPENTERTIME, ");
		sql.append("CATCLASS, ");
		sql.append("CONFIGKEY ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" SERIAL='"+serial+"'");		
		
		try {
			ps = conn.prepareStatement(sql.toString());		
			//ps.setString(1, serial);			
			rs = ps.executeQuery();
		
			while (rs.next()) {		
				marketCarInfoDto = new MarketCarInfoDto();
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setTempLicensePlate(rs.getString("TEMPLICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setStatus(rs.getInt("STATUS"));
				marketCarInfoDto.setCarScore(rs.getInt("CARSCORE"));
				marketCarInfoDto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				marketCarInfoDto.setCarName(rs.getString("CARNAME"));
				marketCarInfoDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				marketCarInfoDto.setBarCodeNum(rs.getInt("BARCODENUM"));
				marketCarInfoDto.setRemark(rs.getString("REMARK"));
				marketCarInfoDto.setIsMatch(rs.getInt("ISMATCH"));
				marketCarInfoDto.setIsShelve(rs.getInt("ISSHELVE"));
				marketCarInfoDto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				marketCarInfoDto.setNewLicensePlate(rs.getString("NEWLICENSEPLATE"));
				marketCarInfoDto.setChgLicensePlateTime(rs.getTimestamp("CHGLICENSEPLATETIME"));
				marketCarInfoDto.setCatClass(rs.getInt("CATCLASS"));
				marketCarInfoDto.setStorageTime(rs.getTimestamp("STORAGETIME"));
				marketCarInfoDto.setConfigKey(rs.getString("CONFIGKEY"));
				marketCarInfoDto.setTmpEnterTime(rs.getTimestamp("TMPENTERTIME"));
				marketCarInfoDto.setTmpStorageTime(rs.getTimestamp("TMPSTORAGETIME"));
				}
			
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		
	}


	@Override
	public void cancelInnerCar(long id) throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		StringBuffer sql = new StringBuffer("");
		sql.append("DELETE FROM  ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" ID=? ");

		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setLong(1, id);
			ps.execute();	
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}		
		
	}


	@Override
	public ControlCarDto findCarById(long id) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		ControlCarDto controlCarDto = new ControlCarDto();
		
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ");
		sql.append("ID, ");
		sql.append("LICENSEPLATE, ");
		sql.append("MEMBERID, ");
		sql.append("IMAGEPATH ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" REGISTERSTATUS IN (1,2) ");
		sql.append(" AND ENTRYSTATUS IN (1,2) ");
		sql.append(" AND ID=? ");
		
		try {

			ps = conn.prepareStatement(sql.toString());
			ps.setLong(1, id);
			rs=ps.executeQuery();						

			while (rs.next()){
				controlCarDto.setId(rs.getLong("ID"));
				controlCarDto.setCarLicense(rs.getString("LICENSEPLATE"));
				controlCarDto.setmId(rs.getInt("MEMBERID"));
				controlCarDto.setImgPath(rs.getString("IMAGEPATH"));
			}
			return controlCarDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		
	}


	@Override
	public int loadGatesInfoCount(String inputTime) {
		PreparedStatement ps = null;
		ResultSet rs = null;
		int count =0;
		StringBuffer sql = new StringBuffer("");
		
		sql.append("SELECT ");
		sql.append("COUNT(*) AS COUNT ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_GATES_INFO);
		sql.append(" WHERE ");
		sql.append(" INPUTTIME>? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, inputTime);
			rs=ps.executeQuery();
			while(rs.next()){
				count = rs.getInt("COUNT");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}


	/**
	 * 查询车辆进出库信息
	 * 
	 * 查询条件:卡片号码，车牌号码，时间段
	 * 
	 */
	@Override
	public List findGatesInfoIOList(String cardNo, String carLicense,
			String period) throws TmsDaoException {
		// 开始掉数据
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<GatesInfoOutDto> list = new ArrayList<GatesInfoOutDto>();

		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append("GATES.ID AS ID, 		");
		sql.append("GATES.CARDID AS CARDID, 		");
		sql.append("GATES.LICENSEPLATE AS LICENSEPLATE, ");
		sql.append("MEM.REALNAME AS SHOPNAME, 		");//和member表关联查询出商铺名字
		sql.append("GATES.IMGPATH AS IMGPATH, 		");
		sql.append("GATES.CHANNELNAME AS CHANNELNAME,");//在字典表中根据代码查询
		sql.append("GATES.INTIME AS INTIME,			");
		sql.append("GATES.OUTTIME AS  OUTTIME,		");
		sql.append("GATES.CARNAME AS  CARNAME		");
		//sql.append("MAX(MARKET.UPDATETIME) AS  UPDATETIME		");
		sql.append(" FROM 							");
		//sql.append(TmsTableNames.TMS_DATES_INFO_OUT);
		sql.append(" GATES 					");
		sql.append(" LEFT JOIN  			");
		sql.append(TmsTableNames.TMS_MEMBER);
		sql.append(" MEM 					");
		sql.append(" ON MEM.MEMBERID =  GATES.MID 	");
//		sql.append(" LEFT JOIN  			");
//		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
//		sql.append(" MARKET 			");
//		sql.append(" ON  MARKET.LICENSEPLATE = GATES.LICENSEPLATE	");
		sql.append(" WHERE 1=1 				"); 	
		//开始判断
		//需要建立一个dto
		//卡号
		if(cardNo!=null && !"".equals(cardNo))
		{
			sql.append(" AND GATES.CARDID ='"+cardNo+"' ");
		}
		//车牌号码
		if(carLicense!=null && !"".equals(carLicense))
		{
			sql.append(" AND GATES.LICENSEPLATE = '"+carLicense+"' ");
		}
		if(period!=null && !"".equals(period))
		{
			sql.append(" AND (DATE_FORMAT(GATES.INTIME,'%Y-%m-%d') >='"+period+"' OR DATE_FORMAT(GATES.OUTTIME,'%Y-%m-%d') >='"+period+"' ) ");	
		}
		
		sql.append(getOrderBySql(gatesInfoIOKeyList));

		GatesInfoOutDto carDto = null;
		try {

			ps = conn.prepareStatement(getSql(sql.toString()));
			rs = ps.executeQuery();
			int i=0;
			while (rs.next()) {
				if(rs.getInt("ID")>0)
				{
					carDto = new GatesInfoOutDto();
					carDto.setCardId(rs.getString("CARDID"));
					carDto.setCarLicense(rs.getString("LICENSEPLATE"));
					if(rs.getString("SHOPNAME")!=null && !"".equals(rs.getString("SHOPNAME")))
					{
						carDto.setShopName(rs.getString("SHOPNAME"));
					}else{
						carDto.setShopName("-");
					}
					carDto.setImgPath(rs.getString("IMGPATH"));
					carDto.setChannelName(rs.getString("CHANNELNAME"));
					
					if(rs.getTimestamp("INTIME")!=null)
					{
						carDto.setInTime(DateUtil.getDateByTimeStampHM(rs.getTimestamp("INTIME")));
					}else{
						carDto.setInTime("-");
					}
					if(rs.getTimestamp("OUTTIME")!=null)
					{
						carDto.setOutTime(DateUtil.getDateByTimeStampHM(rs.getTimestamp("OUTTIME")));
					}else{
						carDto.setOutTime("-");
					}
					if(rs.getString("CARNAME")!=null && !"".equals(rs.getString("CARNAME")))
					{
						carDto.setCarName(rs.getString("CARNAME"));
					}else{
						carDto.setCarName("-");
					}
					
					if(i%2 == 0){
						carDto.setCssFlag(1);
					}else{
						carDto.setCssFlag(2);
					}
					int num = (i+1)+(getPageNo()-1)*10;
					carDto.setNum(num);
					list.add(carDto);
					i++;					
				}
			}
			
			return list;

		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}		
	}



	public List<MarketCarInfoDto> getCarStockCountInfoByMemId(String memId)
	throws TmsDaoException{
		// 开始掉数据
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> list = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append(" SERIAL,");
		sql.append(" LICENSEPLATE,");
		sql.append(" CARNAME,");
		sql.append(" PHOTO_1,");
		sql.append(" CARSCORE,");
		sql.append(" STORAGETIME, ");
		sql.append(" ENTERTIME, ");
		sql.append(" REGISTERSTATUS ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" MEMBERID="+memId);
		// modify by huangheli at 20150808 start
		//sql.append(" AND REGISTERSTATUS<3");
		sql.append(" AND REGISTERSTATUS not in (3,4)  ");
		// modify by huangheli at 20150808 end
		sql.append(" ORDER BY INSERTTIME DESC");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setSerial(rs.getString("SERIAL"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setCarName(rs.getString("CARNAME"));
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setCarScore(rs.getInt("CARSCORE"));
				dto.setStorageTime(rs.getTimestamp("STORAGETIME"));
				dto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				dto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				list.add(dto);
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}	
		return list;
		
	}
	
	

	@Override
	public int findSameSerial(String serial) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		int flg = 1;//1:没有，2：有
		StringBuffer sql = new StringBuffer("SELECT SERIAL");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" SERIAL=?");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, serial);
			rs = ps.executeQuery();
			while(rs.next()){
				flg = 2;
			}
		}  catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}	
		return flg;
	}


	@Override
	public int findUtimeStatus(long id, String uTime) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		int flg = 1;//1:没有，2：有
		StringBuffer sql = new StringBuffer("SELECT 1");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" ID=? ");
		sql.append(" AND UPDATETIME<? ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setLong(1, id);
			ps.setString(2, uTime);
			rs = ps.executeQuery();
			while(rs.next()){
				flg =2;
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}	
		return flg;
	}


	/**
	 * 车辆图片列表李斯特
	 */
	@Override
	public List<MarketCarInfoDto> getCarPhoneInfoList() throws TmsDaoException {
		// 开始掉数据
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> list = new ArrayList<MarketCarInfoDto>();
		/**
		序号	流水号	车牌号码	左前	右前	左后	右后	预售价格(元)	表显里程(公里)	受理时间
		 */
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append("SERIAL, ");
		sql.append("LICENSEPLATE, ");
		sql.append("PHOTO_1, ");
		sql.append("PHOTO_2, ");
		sql.append("PHOTO_3,");
		sql.append("PHOTO_4,");
		sql.append("PRICE,");
		sql.append("MILEAGE,  ");
		sql.append("INSERTTIME,  ");
		sql.append("UPDATETIME,  ");
		sql.append("ENTRYSTATUS  ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE REGISTERSTATUS=1 ");
		sql.append(" AND ((ENTRYSTATUS =2 AND  DATE_FORMAT(INSERTTIME,'%Y-%m-%d') = DATE_FORMAT(SYSDATE(),'%Y-%m-%d')) OR (ENTRYSTATUS IN (3,4) AND DATE_FORMAT(UPDATETIME,'%Y-%m-%d') = DATE_FORMAT(SYSDATE(),'%Y-%m-%d'))) ");
		
		//排序  INSERTTIME
		sql.append(getOrderBySql(carPhotoSortKeyList));

		MarketCarInfoDto carDto = null;
		try {

			ps = conn.prepareStatement(getSql(sql.toString()));
			rs = ps.executeQuery();
			int i=0;
			while (rs.next()) {
				carDto = new MarketCarInfoDto();
				carDto.setSerial(rs.getString("SERIAL"));
				carDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				carDto.setPhoto_1(rs.getString("PHOTO_1"));
				carDto.setPhoto_2(rs.getString("PHOTO_2"));
				carDto.setPhoto_3(rs.getString("PHOTO_3"));
				carDto.setPhoto_4(rs.getString("PHOTO_4"));
				if(rs.getInt("PRICE") == 0)
				{
					carDto.setPhotoPrice("-");
				}else{
					carDto.setPhotoPrice(StringUtil.getPointBetweenThree(rs.getInt("PRICE")));
				}
				if(rs.getInt("MILEAGE") == 0)
				{
					carDto.setMileageStr("-");
				}else{
					carDto.setMileageStr(StringUtil.getPointBetweenThree(rs.getInt("MILEAGE")));
				}
				
				if(rs.getInt("ENTRYSTATUS")==2)
				{
					carDto.setPhotoInsertTime(DateUtil.getTimeByTimeStamp1(rs.getTimestamp("INSERTTIME")));
				}else{
					carDto.setPhotoInsertTime(DateUtil.getTimeByTimeStamp1(rs.getTimestamp("UPDATETIME")));
				}
				
				if(i%2 == 0){
					carDto.setCssFlag(1); 
				}else{
					carDto.setCssFlag(2);
				}
				int num = (i+1)+(getPageNo()-1)*10;
				carDto.setNum(num);
				list.add(carDto);
				i++;
			}
	
			return list;

		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}		
	}
	/**
	 * 载入会员车辆
	 * */

	@Override
	public List<MarketCarInfoDto> findMemberCar(String memberId,int type)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		List<MarketCarInfoDto> memberCarList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append("SERIAL, ");
		sql.append("LICENSEPLATE, ");
		sql.append("CARNAME, ");
		sql.append("PRICE, ");
		sql.append("CARSCORE,");
		sql.append("REGISTERSTATUS, ");
		sql.append("STATUS, ");
		sql.append("INSERTTIME,");
		sql.append("CARTYPE,");
		sql.append("DISPLACEMENT,");
		sql.append("ISSHELVE");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" MEMBERID= "+memberId);		
		if(type == 1){
			sql.append(" AND STATUS=3 ");
		}
		if(type == 2){
			sql.append(" AND (REGISTERSTATUS=2 OR  REGISTERSTATUS=6)"); //WL:20150509
		}
		if(type == 3){
			sql.append(" AND STATUS=5 ");
		}
		if(type == 0){
			sql.append(" AND (REGISTERSTATUS=1 OR REGISTERSTATUS=5)"); //WL:20150509
		}
		if(type == 1){
			sql.append(getOrderBySql(memberCarListZero));
		}else if(type == 3){
			sql.append(getOrderBySql(memberCarListFour));
		}else{
			sql.append(getOrderBySql(memberCarListZero));
		}
		
		try {

			ps = conn.prepareStatement(getSql(sql.toString()));
			rs = ps.executeQuery();
			
			while (rs.next()) {
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setSerial(rs.getString("SERIAL"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setCarName(rs.getString("CARNAME"));
				dto.setPrice(rs.getInt("PRICE"));
				dto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				dto.setStatus(rs.getInt("STATUS"));
				dto.setCarScore(rs.getInt("CARSCORE"));
				dto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				dto.setCarType(rs.getInt("CARTYPE"));
				dto.setDisplacementStr(StringUtil.transOnes(rs.getInt("DISPLACEMENT")));
				dto.setIsShelve(rs.getInt("ISSHELVE"));
				memberCarList.add(dto);
			}
		 return memberCarList;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}		
		
	}
	
	@Override
	public List<MarketCarInfoDto> findAttnCar(String attnId, int type)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		List<MarketCarInfoDto> memberCarList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append("CAR.SERIAL SERIAL, ");
		sql.append("CAR.LICENSEPLATE LICENSEPLATE, ");
		sql.append("CAR.CARNAME CARNAME, ");
		sql.append("CAR.PRICE PRICE, ");
		sql.append("CAR.CARSCORE CARSCORE,");
		sql.append("CAR.REGISTERSTATUS REGISTERSTATUS, ");
		sql.append("CAR.STATUS STATUS, ");
		sql.append("CAR.INSERTTIME INSERTTIME,");
		sql.append("CAR.CARTYPE CARTYPE,");
		sql.append("CAR.DISPLACEMENT DISPLACEMENT,");
		sql.append("CAR.ISSHELVE ISSHELVE");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" AS CAR,");
		sql.append(TmsTableNames.TMS_TRANSFER_ACCEPTED_INFO );
		sql.append(" as B ");
		sql.append(" WHERE ");
		sql.append(" B.ATTNID= "+attnId);
		sql.append(" AND B.BASICCARID = CAR.SERIAL");		
		if(type == 1){
			sql.append(" AND CAR.STATUS=3 ");
		}
		if(type == 2){
			// modify by huangheli at 20150813 start
			//sql.append(" AND CAR.STATUS=4 ");
			sql.append(" AND (CAR.REGISTERSTATUS=2 OR CAR.REGISTERSTATUS=6) ");//WL:20150509
			// modify by huangheli at 20150813 end
		}
		if(type == 3){
			sql.append(" AND CAR.STATUS=5 ");
		}
		if(type == 0){
			// modify by huangheli at 20150813 start
			//sql.append(" AND CAR.STATUS=1 ");
			sql.append(" AND (CAR.REGISTERSTATUS=1 OR CAR.REGISTERSTATUS=5)");//WL:20150509
			// modify by huangheli at 20150813 end
		}
		// modify by huangheli at 20150813 start
//		if(type == 2){
//			sql.append(getOrderBySql(memberCarListThree));
//		}else 
		// modify by huangheli at 20150813 end
		if(type == 1){
			sql.append(getOrderBySql(memberCarListZero));
		}else if(type == 3){
			sql.append(getOrderBySql(memberCarListFour));
		}else{
			sql.append(getOrderBySql(memberCarListZero));
		}
		
		
		
		try {

			ps = conn.prepareStatement(getSql(sql.toString()));
			rs = ps.executeQuery();
			
			while (rs.next()) {
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setSerial(rs.getString("SERIAL"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setCarName(rs.getString("CARNAME"));
				dto.setPrice(rs.getInt("PRICE"));
				dto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				dto.setStatus(rs.getInt("STATUS"));
				dto.setCarScore(rs.getInt("CARSCORE"));
				dto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				dto.setCarType(rs.getInt("CARTYPE"));
				dto.setDisplacementStr(StringUtil.transOnes(rs.getInt("DISPLACEMENT")));
				dto.setIsShelve(rs.getInt("ISSHELVE"));
				memberCarList.add(dto);
			}
				return memberCarList;
				

		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}		
		
	}



	
	
	/**
	 * 载入商户车辆数量
	 * */

	@Override
	public int loadMemberCarCount(String memberId, int type)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		int count = 0;
		sql.append("SELECT ");
		sql.append("COUNT(*) AS COUNT ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" MEMBERID= ?");
		if(type == 2){//待办中
			sql.append(" AND STATUS=2");
		}else if(type == 3){//过户中
			sql.append(" AND STATUS=3 ");
		}else if(type == 4){//出库车辆
			//modify by huangheli 20150813 start
			sql.append(" AND REGISTERSTATUS=2 ");
			//sql.append(" AND STATUS=4");
			//modify by huangheli 20150813 end
		}else if(type == 5){
			sql.append(" AND STATUS=5");
		}else if(type == 0){
			//modify by huangheli 20150813 start
			//sql.append(" AND STATUS=1");
			sql.append(" AND REGISTERSTATUS=1");
			//modify by huangheli 20150813 end
		}
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, memberId);
			rs=ps.executeQuery();
			while(rs.next()){
				count = rs.getInt("COUNT");
			}
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return count;
	}

	/**
	 * 载入商户车辆数量
	 * */

	@Override
	public int loadAttnCarCount(String attnId, int type)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		int count = 0;
		sql.append("SELECT ");
		sql.append("COUNT(*) AS COUNT ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO );
		sql.append(" as A ,");
		sql.append(TmsTableNames.TMS_TRANSFER_ACCEPTED_INFO );
		sql.append(" as B ");
		sql.append(" WHERE ");
		sql.append(" B.ATTNID= ?");
		sql.append(" AND B.BASICCARID = A.SERIAL");
		if(type == 2){//待办中
			sql.append(" AND A.STATUS=2");
		}else if(type == 3){//过户中
			sql.append(" AND A.STATUS=3 ");
		}else if(type == 4){//出库车辆
			//modify by huangheli 20150813 start
			//sql.append(" AND A.STATUS=4");
			sql.append(" AND A.REGISTERSTATUS=2");
			//modify by huangheli 20150813 end
		}else if(type == 5){
			sql.append(" AND A.STATUS=5");
		}else if(type == 0){
			//modify by huangheli 20150813 start
			//sql.append(" AND A.STATUS=1");
			sql.append(" AND A.REGISTERSTATUS=1");
			//modify by huangheli 20150813 end
		}
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, attnId);
			rs=ps.executeQuery();
			while(rs.next()){
				count = rs.getInt("COUNT");
			}
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return count;
	}

	/**
	 * 商户待办中列表
	 * */
	@Override
	public List<MarketCarInfoDto> findMemberProxyCar(String memberId,int type)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		List<MarketCarInfoDto> memberCarList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append("CAR.SERIAL,");
		sql.append("CAR.LICENSEPLATE,");
		sql.append("CAR.CARNAME,");
		sql.append("CAR.DISPLACEMENT,");
		sql.append("B.NEWCAROWNER,");
		sql.append("B.SERIAL AS TRANSFERSERIAL,");
		sql.append("B.EXTENDEDPRICE,");
		sql.append("C.AGENCYPRICE,");		
		sql.append("DATE_FORMAT(B.AGENTTIME,'%Y-%m-%d') AS AGENTTIME,");
		sql.append("B.STATUS");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" AS CAR,");
		sql.append(TmsTableNames.TMS_TRANSFER_ACCEPTED_INFO);
		sql.append(" AS B,");
		sql.append(TmsTableNames.TMS_TRANSFER_FINANCE_INFO);
		sql.append(" AS C");
		sql.append(" WHERE ");
		sql.append(" CAR.SERIAL = B.BASICCARID ");
		sql.append(" AND B.SERIAL = C.SERIAL");
		sql.append(" AND CAR.STATUS=2");
		if(type == 1){
			sql.append(" AND CAR.MEMBERID="+memberId);
		}else if(type == 2){
			sql.append(" AND B.ATTNID="+memberId);
		}
		
		//排序  INSERTTIME
		sql.append(getOrderBySql(memberCarListOne));
		
		try {
			ps = conn.prepareStatement(getSql(sql.toString()));
			rs = ps.executeQuery();
			while (rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setSerial(rs.getString("SERIAL"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setCarName(rs.getString("CARNAME"));
				dto.setDisplacementStr(StringUtil.transOnes(rs.getInt("DISPLACEMENT")));
				dto.setNewCarOwner(rs.getString("NEWCAROWNER"));
				dto.setAgencyprice(rs.getInt("AGENCYPRICE"));
				dto.setExtendedprice(rs.getInt("EXTENDEDPRICE"));
				dto.setAgencytime(rs.getDate("AGENTTIME"));
				dto.setStatusTransfer(rs.getInt("STATUS"));
				dto.setTransferSerial(rs.getString("TRANSFERSERIAL"));
				memberCarList.add(dto);
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		
		
		return memberCarList;
	}

	@Override
	public void updateLicenseplateBySerial(String licensePlate, String tmpLicenseplate, String serial) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		if(!"".equals(licensePlate)){
			sql.append(" LICENSEPLATE= '"+licensePlate+"' ");
		}if(!"".equals(tmpLicenseplate)){
			if(!"".equals(licensePlate)){			
				sql.append(",");
			}
			sql.append(" TEMPLICENSEPLATE= '"+tmpLicenseplate+"' ");
		}
		sql.append(" WHERE  ");
		sql.append(" SERIAL= '"+serial+"' ");
		try {			
			ps = conn.prepareStatement(sql.toString());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}


	/**
	 * 
	 * 评估更新库存
	 */

	@Override
	public void updateCarInfoAtAssess(MarketCarInfoDto marketCarInfoDto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" LICENSEPLATE=?,  ");
		sql.append(" VIN=?,  ");
		sql.append(" VENDORCODE=?,  ");
		sql.append(" MODELCODE=?,  ");
		sql.append(" CARTYPE=?,  ");
		sql.append(" COLOR=?,  ");
		sql.append(" CARUSE=?,  ");
		sql.append(" REGDATE=?,  ");
		sql.append(" SENDCARDDATE=?,  ");
		sql.append(" UPDATEUSERID=?,  ");
		sql.append(" CAROWNER=?,  ");
		sql.append(" UPDATETIME=SYSDATE(),  ");
		sql.append(" PRICE=?  ");
		sql.append(" WHERE  ");
		sql.append(" SERIAL=? ");
		try {
			
			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, marketCarInfoDto.getLicensePlate());
			ps.setString(2, marketCarInfoDto.getVin());
			ps.setString(3, marketCarInfoDto.getVendorCode());
			ps.setString(4, marketCarInfoDto.getModelCode());
			ps.setInt(5, marketCarInfoDto.getCarType());
			ps.setInt(6, marketCarInfoDto.getColor());
			ps.setDouble(7, marketCarInfoDto.getCarUse());
			ps.setString(8, marketCarInfoDto.getRegDate());
			ps.setString(9, marketCarInfoDto.getSendCardDate());			
			ps.setInt(10, marketCarInfoDto.getUpdateUserId());
			ps.setString(11, marketCarInfoDto.getCarOwner());
			ps.setInt(12, marketCarInfoDto.getPrice());
			ps.setString(13, marketCarInfoDto.getSerial());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}

	
	
	@Override
	public void updateCarShelve(String serial, String shelve) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" ISSHELVE=?");
		sql.append(" WHERE  ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, shelve);
			ps.setString(2, serial);
			ps.executeUpdate();
			} catch (SQLException e) {
				throw new TmsDaoException(e.toString());
			}finally {
				super.close(rs, ps);
			}	
	    }


	@Override
	public void updateCarEasy(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append("PRICE=?,");
		sql.append("REGDATE=?,");
		sql.append("DISPLACEMENT=?,");
		sql.append("MILEAGE=?,");
		sql.append("GEARBOX=?,");
		sql.append("SENDCARDDATE=?,");
		sql.append("VENDORID=?,");
		sql.append("BRANDID=?,");
		sql.append("CARSTYLEID=?,");
		sql.append("MEMBERID=?,");
		sql.append("CARSCORE=?,");
		sql.append("ATTESTSTATUS=?,");
		sql.append("STORAGETIME=SYSDATE(),");
		sql.append("UPDATETIME=SYSDATE(),");
		sql.append("UPDATEUSERID=?,");
		sql.append("CAROWNER=?");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		
try {
			
			ps = conn.prepareStatement(sql.toString());
			
			ps.setInt(1, dto.getPrice());
			ps.setString(2, dto.getRegDate());
			ps.setInt(3, dto.getDisplacement());
			ps.setInt(4, dto.getMileage());
			ps.setInt(5, dto.getGearbox());
			ps.setString(6, dto.getSendCardDate());
			ps.setString(7, dto.getVendorId());
			ps.setString(8, dto.getBrandId());
			ps.setString(9, dto.getCarStyleId());
			ps.setInt(10, dto.getMemberId());
			ps.setInt(11, dto.getCarScore());
			ps.setInt(12, dto.getAttestStatus());
			ps.setInt(13, dto.getUpdateUserId());
			ps.setString(14, dto.getCarOwner());
			ps.setString(15, dto.getSerial());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}

	/**
	 * 待办受理更新库存信息
	 */
	@Override
	public void updateMarketInfoByLicensePlate(MarketCarInfoDto dto) throws TmsDaoException {

		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" CARNAME=?,");
		sql.append(" GEARBOX=?,");
		sql.append(" MODELCODE=?,");
		sql.append(" VENDORCODE=?,");
		sql.append(" CARTYPE=?,");
		sql.append(" ENGINE=?,");
		sql.append(" COLOR=?,");
		sql.append(" COUNTRYSTYLE=?,");
		sql.append(" DISPLACEMENT=?,");
		sql.append(" FUELTYPE=?,");
		sql.append(" PASSENGER=?,");
		sql.append(" LOADQUALITY=?,");
		sql.append(" CARUSE=?,");
		sql.append(" CARDTYPE=?,");
		sql.append(" YEARCAREFULPERIOD=?,");
		sql.append(" JQX=?,");
		sql.append(" REGISTERCARDNO=?,");
		sql.append(" REGDATE=?,");
		sql.append(" SENDCARDDATE=?,");
		sql.append(" OWNERTYPE=?,");
		sql.append(" OWNERPHONE=?,");
		sql.append(" CAROWNER=?,");
		sql.append(" CAROWNERIDCARDNO=?,");
		sql.append(" OWNERADDRESS=?,");
		sql.append(" CARSTYLEID=?,");
		sql.append(" BRANDID=?,");
		sql.append(" VENDORID=?,");
		sql.append(" UPDATETIME=SYSDATE(),");
		sql.append(" UPDATEUSERID=?, ");
		sql.append(" CARSCORE=?, ");
		sql.append(" MILEAGE=?, ");
		sql.append(" OWNERORGNO=?, ");
		sql.append(" MEMBERID=?, ");
		sql.append(" STATUS=?, "); 
		sql.append(" VIN=? "); 
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			
			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, dto.getCarName());
			ps.setLong(2, dto.getGearbox());
			ps.setString(3, dto.getModelCode());
			ps.setString(4, dto.getVendorCode());
			ps.setInt(5, dto.getCarType());
			ps.setString(6, dto.getEngine());
			ps.setInt(7, dto.getColor());
			ps.setInt(8, dto.getCountryStyle());
			ps.setInt(9, dto.getDisplacement());
			ps.setLong(10, dto.getFuelType());
			ps.setInt(11, dto.getPassenger());
			ps.setInt(12, dto.getLoadquality());
			ps.setInt(13, dto.getCarUse());
			ps.setInt(14, dto.getCardType());
			ps.setString(15, dto.getYearCarefulPeriod());
			ps.setString(16, dto.getJqx());
			ps.setString(17, dto.getRegisterCardNo());
			ps.setString(18, dto.getRegDate());
			ps.setString(19, dto.getSendCardDate());
			ps.setInt(20, dto.getOwnerType());
			ps.setString(21, dto.getOwnerPhone());
			ps.setString(22, dto.getCarOwner());
			ps.setString(23, dto.getCarOwnerIdCardNo());
			ps.setString(24, dto.getOwnerAddress());
			ps.setString(25, dto.getCarStyleId());
			ps.setString(26, dto.getBrandId());
			ps.setString(27, dto.getVendorId());
			ps.setInt(28, dto.getUpdateUserId());
			ps.setInt(29, dto.getCarScore());
			ps.setInt(30, dto.getMileage());
			ps.setString(31, dto.getOwnerOrgNo());
			ps.setInt(32, dto.getMemberId());
			ps.setInt(33, dto.getStatus());
			ps.setString(34, dto.getVin());
			ps.setString(35, dto.getSerial());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}
	
	

	@Override
	public TempLicensePlate findTempLicensePlate(String licensePlate) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		boolean flag = false;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID, ");
		sql.append(" LICENSEPLATE, ");
		sql.append(" ISUSE ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_TEMP_LICENSEPLATE);
		sql.append(" WHERE ");
		sql.append(" LICENSEPLATE=? ");
		TempLicensePlate po = null;
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, licensePlate);
			rs = ps.executeQuery();
			while(rs.next()){
				po = new TempLicensePlate();
				po.setId(rs.getString("ID"));
				po.setIsUse(rs.getInt("ISUSE"));
				po.setLicensePlate(rs.getString("LICENSEPLATE"));
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return po;
	}


	/**
	 * 判断是否有相同车牌号码 并且状态不为过期的车辆
	 * */
	@Override
	public boolean findInsertCarFlag(String licensePlate) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		boolean flag = false;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" LICENSEPLATE=? ");
		// modify by huangheli at 20150808 start
		//sql.append(" AND REGISTERSTATUS < 3");
		sql.append(" AND REGISTERSTATUS not in (3,4) ");
		// modify by huangheli at 20150808 end
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, licensePlate);
			rs = ps.executeQuery();
			while(rs.next()){
				flag =true;
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return flag;
	}
	
	/**
	 * 判断是否有相同车辆编号 并且状态不为过期的车辆
	 * */
	@Override
	public boolean findCarbySerial(String serial)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		boolean flag = false;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		sql.append(" AND REGISTERSTATUS not in (3,4) ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, serial);
			rs = ps.executeQuery();
			while(rs.next()){
				flag =true;
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return flag;
	}

	@Override
	public Integer findCarIdbySerial(String serial)throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		Integer id = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		sql.append(" AND REGISTERSTATUS not in (3,4) ");

		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, serial);
			rs = ps.executeQuery();
			int i=0;
			while(rs.next()){
				id=rs.getInt("ID");
				i++;
			}
			if(i>1){
				throw new TmsDaoException("车辆编号重复");
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return id;
	}

	
	public List<BaseCarInfoDto> findBaseCarInfoVinList(String vin)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<BaseCarInfoDto> dtoList = new ArrayList<BaseCarInfoDto>();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID, ");
		sql.append(" VIN ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_BASE_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" VIN LIKE '%"+vin+"%' ");
		sql.append(" ORDER BY VIN ASC");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				BaseCarInfoDto dto = new BaseCarInfoDto();
				dto.setId(rs.getInt("ID"));
				dto.setVin(rs.getString("VIN"));
				dtoList.add(dto);
			}
			return dtoList;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
	}
	

	/**
	 * vin码检索base表信息
	 */
	@Override
	public BaseCarInfoDto findCarBaseInfoByVin(String vin)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		BaseCarInfoDto baseCarInfoDto = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("LICENSEPLATE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("VENDORID ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_BASE_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" VIN=?");

		
		try {

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, vin);			
			rs = ps.executeQuery();
			int i =1;
			
			while (rs.next()) {
				baseCarInfoDto = new BaseCarInfoDto();
				if(i==2){
					break;
				}
				baseCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				baseCarInfoDto.setVin(rs.getString("VIN"));
				baseCarInfoDto.setEngine(rs.getString("ENGINE"));
				baseCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				baseCarInfoDto.setColor(rs.getInt("COLOR"));
				baseCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				baseCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				baseCarInfoDto.setRegDate(rs.getString("REGDATE"));
				baseCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				baseCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				baseCarInfoDto.setJqx(rs.getString("JQX"));
				baseCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				baseCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				baseCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				baseCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				baseCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				baseCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				baseCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				baseCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				baseCarInfoDto.setVendorId(rs.getString("VENDORID"));
				baseCarInfoDto.setBrandId(rs.getString("BRANDID"));
				baseCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				baseCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				baseCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				baseCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				baseCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				baseCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				baseCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				baseCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				i++;
			}
			return baseCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}


	@Override
	public MarketCarInfoDto searchAllCarByLicensePlate(String licensePlate)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT SERIAL,");
		sql.append("ID,");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("LICENSEPLATE,");
		sql.append("PRICE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("MEMBERID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("ATTRIBUTE,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("UPDATETIME,");
		sql.append("UPDATEUSERID,");
		sql.append("PHOTO_1, ");
		sql.append("PHOTO_2, ");
		sql.append("PHOTO_3, ");
		sql.append("PHOTO_4, ");
		sql.append("PHOTO_5, ");
		sql.append("PHOTO_6, ");
		sql.append("PHOTO_7, ");
		sql.append("PHOTO_8, ");
		sql.append("IMAGEPATH, ");
		sql.append("REGISTERSTATUS, ");
		sql.append("ENTRYSTATUS, ");	
		sql.append("INSERTUSERID, ");
		sql.append("VENDORID ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" LICENSEPLATE=?");
		sql.append(" ORDER BY ID DESC");
		
		
		try {

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, licensePlate);			
			rs = ps.executeQuery();
			int i =1;
			
			while (rs.next()) {
				if(i==2){
					break;
				}
				marketCarInfoDto = new MarketCarInfoDto();
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setImagePath(rs.getString("IMAGEPATH"));
				i++;
			}
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}

	/**
	 * PAD库存车辆录入上传更新库存表
	 */
	@Override
	public void updateCarAtPad(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append("PRICE=?, ");
		sql.append("MILEAGE=?,");
		sql.append("PHOTO_1=?, ");
		sql.append("PHOTO_2=?, ");
		sql.append("PHOTO_3=?, ");
		sql.append("PHOTO_4=?, ");
		sql.append("PHOTO_5=?, ");
		sql.append("PHOTO_6=?, ");
		sql.append("PHOTO_7=?, ");
		sql.append("PHOTO_8=?, ");
		sql.append("MEMBERID=?, ");
		sql.append("UPDATETIME=SYSDATE(),");
		sql.append("UPDATEUSERID=? ");
		sql.append("WHERE ");
		sql.append("SERIAL=? ");
		try {
			
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, dto.getPrice());
			ps.setInt(2, dto.getMileage());
			ps.setString(3, dto.getPhoto_1());
			ps.setString(4, dto.getPhoto_2());
			ps.setString(5, dto.getPhoto_3());
			ps.setString(6, dto.getPhoto_4());
			ps.setString(7, dto.getPhoto_5());
			ps.setString(8, dto.getPhoto_6());
			ps.setString(9, dto.getPhoto_7());
			ps.setString(10, dto.getPhoto_8());
			ps.setInt(11, dto.getMemberId());
			ps.setInt(12, dto.getUpdateUserId());
			ps.setString(13, dto.getSerial());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			super.close(rs, ps);
		}		
	}

	
	@Override
	public void updateCarPhotoBySerial(String serial, MarketCarInfoDto marketCarInfoDto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" PHOTO_1=?, ");
		sql.append(" PHOTO_2=?, ");
		sql.append(" PHOTO_3=?, ");
		sql.append(" PHOTO_4=?, ");
		sql.append(" PHOTO_5=?, ");
		sql.append(" PHOTO_6=?, ");
		sql.append(" PHOTO_7=?, ");
		sql.append(" PHOTO_8=?, ");
		sql.append(" UPDATEUSERID=?, ");
		sql.append(" UPDATETIME=SYSDATE()");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, marketCarInfoDto.getPhoto_1());
			ps.setString(2, marketCarInfoDto.getPhoto_2());
			ps.setString(3, marketCarInfoDto.getPhoto_3());
			ps.setString(4, marketCarInfoDto.getPhoto_4());
			ps.setString(5, marketCarInfoDto.getPhoto_5());
			ps.setString(6, marketCarInfoDto.getPhoto_6());
			ps.setString(7, marketCarInfoDto.getPhoto_7());
			ps.setString(8, marketCarInfoDto.getPhoto_8());
			ps.setInt(9, marketCarInfoDto.getInsertUserId());
			ps.setString(10, marketCarInfoDto.getSerial());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
	}

	
	@Override
	public void updateCarEvaluate(String serial,MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append("ATTESTSTATUS=?, ");
		sql.append("INTERNALSCORE=?, ");
		sql.append("EXTERNALSCORE=?, ");
		sql.append("DETECTREMARK=?, ");
		sql.append("UPDATEUSERID=?, ");
		sql.append("UPDATETIME=SYSDATE()");
		sql.append("WHERE ");
		sql.append("SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, dto.getAttestStatus());
			ps.setString(2, dto.getInternalScore());
			ps.setString(3, dto.getExternalScore());
			ps.setString(4, dto.getDetectRemark());
			ps.setInt(5, dto.getUpdateUserId());
			ps.setString(6, dto.getSerial());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}		
	}
	
	@Override
	public void updateCarPic(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append("PHOTO_1=?, ");
		sql.append("PHOTO_2=?, ");
		sql.append("PHOTO_3=?, ");
		sql.append("PHOTO_4=?, ");
		sql.append("ENTRYSTATUS=?, ");
		sql.append("UPDATETIME=SYSDATE(),");
		sql.append("INSERTUSERID=? ");
		sql.append("WHERE ");
		sql.append("LICENSEPLATE=? ");
		try {
			
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, dto.getPhoto_1());
			ps.setString(2, dto.getPhoto_2());
			ps.setString(3, dto.getPhoto_3());
			ps.setString(4, dto.getPhoto_4());
			ps.setInt(5, dto.getEntryStatus());
			ps.setInt(6, dto.getInsertUserId());
			ps.setString(7, dto.getLicensePlate());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}				
	}

	/**
	 * 
	 */
	@Override
	public void insertCarInfo(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("INSERT INTO ");
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
			sql.append("(");
			sql.append("PRICE, ");
			sql.append("MILEAGE,");
			sql.append("PHOTO_1, ");
			sql.append("PHOTO_2, ");
			sql.append("PHOTO_3, ");
			sql.append("PHOTO_4, ");
			sql.append("PHOTO_5, ");
			sql.append("PHOTO_6, ");
			sql.append("PHOTO_7, ");
			sql.append("PHOTO_8, ");
			sql.append("MEMBERID, ");
			sql.append("INSERTTIME,");
			sql.append("INSERTUSERID, ");
			sql.append("LICENSEPLATE, ");
			sql.append("ENTRYSTATUS, ");
			sql.append("REGISTERSTATUS, ");
			sql.append("STATUS, "); 
			sql.append("ATTESTSTATUS, ");
			sql.append("SERIAL, ");
			sql.append("UPDATEUSERID, ");
			sql.append("UPDATETIME, ");
			sql.append("STORAGETIME ");
			

			sql.append("  ) VALUES ( ");
			sql.append(" ?,?,?,?,?,?,?,?,?,?,?,SYSDATE(),?,?" +
						",?,?,?,?,?,?, SYSDATE(),SYSDATE())");

			ps = conn.prepareStatement(sql.toString());
			
			ps.setInt(1, dto.getPrice());
			ps.setInt(2, dto.getMileage());
			ps.setString(3, dto.getPhoto_1());
			ps.setString(4, dto.getPhoto_2());
			ps.setString(5, dto.getPhoto_3());
			ps.setString(6, dto.getPhoto_4());
			ps.setString(7, dto.getPhoto_5());
			ps.setString(8, dto.getPhoto_6());
			ps.setString(9, dto.getPhoto_7());
			ps.setString(10, dto.getPhoto_8());
			ps.setInt(11, dto.getMemberId());
			ps.setInt(12, dto.getInsertUserId());
			ps.setString(13, dto.getLicensePlate());
			ps.setInt(14, dto.getEntryStatus());
			ps.setInt(15, dto.getRegisterStatus());
			ps.setInt(16, dto.getStatus());
			ps.setInt(17, dto.getAttestStatus());
			ps.setString(18, dto.getSerial());
			ps.setInt(19, dto.getUpdateUserId());
	
			ps.executeUpdate();
			
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}		
	}

	@Override
	public void updateCarInfoWithWeiChat(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("INSERT INTO ");
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
			sql.append("(");
			sql.append("COLOR, ");
			sql.append("LICENSEPLATE, ");
			sql.append("ISSHELVE, ");
			sql.append("ENTRYSTATUS, ");
			sql.append("REGISTERSTATUS, ");
			sql.append("MEMBERID, ");
			sql.append("CHARGESTARTDATE, ");
			sql.append("INSERTTIME, ");
			sql.append("UPDATETIME, ");
			sql.append("INSERTUSERID, ");
			sql.append("UPDATEUSERID");

			sql.append("  ) VALUES ( ");
			sql.append(" ?,?,?,?,?,?,NULL,SYSDATE(),SYSDATE(),1,1)");

			ps = conn.prepareStatement(sql.toString());

			ps.setInt(1, dto.getColor());
			ps.setString(2, dto.getLicensePlate());
			ps.setInt(3, dto.getIsShelve());
			ps.setInt(4, dto.getEntryStatus());
			ps.setInt(5, dto.getRegisterStatus());
			ps.setInt(6, dto.getMemberId());

			ps.executeUpdate();


		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}

    /**
	 * 
	 */
	@Override
	public void insertCarInfoWithWeiChat(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("INSERT INTO ");
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
			sql.append("(");
			sql.append("SERIAL, ");
			sql.append("LICENSEPLATE, ");
			sql.append("PRICE, ");
			sql.append("MILEAGE,");
			sql.append("PHOTO_1, ");
			sql.append("MEMBERID, ");
			sql.append("ENTRYSTATUS, ");
			sql.append("REGISTERSTATUS, ");
			sql.append("STATUS, "); 
			sql.append("ATTESTSTATUS, ");
			sql.append("VENDORID, ");
			sql.append("BRANDID, ");
			sql.append("CARSTYLEID, ");
			sql.append("COLOR, ");
			sql.append("JQX, ");
			sql.append("YEARCAREFULPERIOD, ");
			sql.append("CAROWNER, ");
			sql.append("INSERTTIME,");
			sql.append("INSERTUSERID, ");
			sql.append("UPDATETIME, ");
			sql.append("UPDATEUSERID ");
			sql.append("  ) VALUES ( ");
			sql.append(" ?,?,?,?,?,?,?,?,?,?,?,?,?,?" +
						",?,?,?, SYSDATE(),?, SYSDATE(),?)");

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, dto.getSerial());
			ps.setString(2, dto.getLicensePlate());
			ps.setInt(3, dto.getPrice());
			ps.setInt(4, dto.getMileage());
			ps.setString(5, dto.getPhoto_1());
			ps.setInt(6, dto.getMemberId());
			ps.setInt(7, dto.getEntryStatus());
			ps.setInt(8, dto.getRegisterStatus());
			ps.setInt(9, dto.getStatus());
			ps.setInt(10, dto.getAttestStatus());
			ps.setString(11, dto.getVendorId());
			ps.setString(12, dto.getBrandId());
			ps.setString(13, dto.getCarStyleId());
			ps.setInt(14, dto.getColor());
			ps.setString(15, dto.getJqx());
			ps.setString(16, dto.getYearCarefulPeriod());
			ps.setString(17, dto.getCarOwner());
			ps.setInt(18, dto.getInsertUserId());
			ps.setInt(19, dto.getUpdateUserId());
	
			ps.executeUpdate();
			
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}		
	}
 

	@Override
	public void updateCarInfoAtCheck(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" OWNERTYPE=?, ");
		sql.append(" UPDATEUSERID=?, ");
		sql.append(" UPDATETIME=SYSDATE(),");
		sql.append(" STATUS=?  ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			
			ps = conn.prepareStatement(sql.toString());
			
//			ps.setString(1, dto.getCarOwner());
			ps.setInt(1, dto.getOwnerType());
			ps.setInt(2, dto.getUpdateUserId());
			ps.setInt(3, dto.getStatus());
			ps.setString(4, dto.getSerial());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}		
	}


	@Override
	public void insertEasyCarInfo(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("INSERT INTO ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append("(");
		sql.append(" SERIAL ,");
		sql.append("VIN,");
		sql.append("LICENSEPLATE, ");
		sql.append("CAROWNER, ");
		sql.append("MEMBERID, ");
//		sql.append("CARDTYPE,");
		sql.append("REGISTERSTATUS,");
		sql.append("ENTRYSTATUS,");
		sql.append("STATUS,");
		sql.append("ATTESTSTATUS,");
		sql.append("INSERTUSERID,");
		sql.append("UPDATEUSERID,");
		sql.append("CARSCORE,");
		sql.append("STORAGETIME,");
		sql.append("INSERTTIME,");
		sql.append("UPDATETIME,");
		sql.append("PRICE,");
		sql.append("REGDATE,");
		sql.append("DISPLACEMENT,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("VENDORID,");
		sql.append("BRANDID,");
		sql.append("CARSTYLEID,");
		sql.append("CARNAME,");
		sql.append("COLOR,");
		sql.append("TEMPLICENSEPLATE,");
		sql.append("PHOTO_1,");
		sql.append("PHOTO_2,");
		sql.append("PHOTO_3,");
		sql.append("PHOTO_4,");
		sql.append("PHOTO_5,");
		sql.append("PHOTO_6,");
		sql.append("PHOTO_7,");
		sql.append("PHOTO_8,");
		sql.append("JQX,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("CATCLASS,");
		sql.append("ISMATCH");
		sql.append(",isShelve");
		sql.append("  ) VALUES ( ");
		sql.append(" ?,?,?,'',?,?,?,?,?,?,?,?,SYSDATE(),SYSDATE(),SYSDATE(),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, dto.getSerial());
			ps.setString(2, dto.getVin());
			ps.setString(3, dto.getLicensePlate());
			ps.setInt(4, dto.getMemberId());
			ps.setInt(5, dto.getRegisterStatus());
			ps.setInt(6, dto.getEntryStatus());
			ps.setInt(7, dto.getStatus());
			ps.setInt(8, dto.getAttestStatus());
			ps.setInt(9, dto.getInsertUserId());
			ps.setInt(10, dto.getUpdateUserId());
			ps.setInt(11, dto.getCarScore());
			ps.setInt(12, dto.getPrice());
			ps.setString(13, dto.getRegDate());
			ps.setInt(14, dto.getDisplacement());
			ps.setInt(15, dto.getMileage());
			ps.setInt(16, dto.getGearbox());
			ps.setString(17, dto.getSendCardDate());
			ps.setString(18, dto.getVendorId());
			ps.setString(19, dto.getBrandId());
			ps.setString(20, dto.getCarStyleId());
			ps.setString(21, dto.getCarName());
			ps.setInt(22, dto.getColor());
			ps.setString(23, dto.getTempLicensePlate());
			ps.setString(24, dto.getPhoto_1());
			ps.setString(25, dto.getPhoto_2());
			ps.setString(26, dto.getPhoto_3());
			ps.setString(27, dto.getPhoto_4());
			ps.setString(28, dto.getPhoto_5());
			ps.setString(29, dto.getPhoto_6());
			ps.setString(30, dto.getPhoto_7());
			ps.setString(31, dto.getPhoto_8());
			ps.setString(32, dto.getJqx());
			ps.setString(33, dto.getCompanyContactPerson());
			ps.setString(34, dto.getCompanyContactPhone());
			ps.setString(35, dto.getYearCarefulPeriod());
			ps.setInt(36, dto.getCatClass());
			ps.setInt(37, dto.getIsMatch());
			ps.setInt(38, dto.getIsShelve());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
	}


	@Override
	public void updateRegisterStatus(MarketCarInfoDto dto,int type)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		if(type == 1){
			sql.append(" REGISTERSTATUS=1, ");
			sql.append(" STORAGETIME=SYSDATE()");
		}else{
			sql.append(" REGISTERSTATUS=2, ");
			sql.append(" ENTERTIME=SYSDATE()");
		}		
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, dto.getSerial());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
	}


	@Override
	public void updateCarStatus(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" STATUS=?,");
		sql.append(" REGISTERSTATUS=?, ");
		sql.append(" UPDATEUSERID=?, ");
		sql.append(" UPDATETIME=SYSDATE() ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, dto.getStatus());
			ps.setInt(2, dto.getRegisterStatus());
			ps.setInt(3, dto.getUpdateUserId());
			ps.setString(4, dto.getSerial());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}		
	}

	
	
	@Override
	public void updateCarStatusByLicenseplate(int status, String Licenseplate) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" STATUS=?,");
		sql.append(" UPDATETIME=SYSDATE() ");
		sql.append(" WHERE ");
		sql.append(" LICENSEPLATE=? ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, status);
			ps.setString(2, Licenseplate);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}		
	}


	@Override
	public void updateCarStatusOnly(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" STATUS=?,");
		sql.append(" UPDATEUSERID=?, ");
		sql.append(" UPDATETIME=SYSDATE() ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, dto.getStatus());
			ps.setInt(2, dto.getUpdateUserId());
			ps.setString(3, dto.getSerial());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}		
	}

	@Override
	public int findCarCount(int type) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		int count = 0;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT COUNT(*) AS COUNT");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);		
		if(type == 1){
			sql.append(" WHERE ");
			sql.append(" REGISTERSTATUS=1");
		}		
		if(type == 2){
			sql.append(" WHERE ");
			sql.append("REGISTERSTATUS=1 or REGISTERSTATUS=2");
		}
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				count = rs.getInt("COUNT");
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
		return count;
	}


	@Override
	public int findCarCountByMem(int type, String memId) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		int count = 0;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT COUNT(*) AS COUNT");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);	
		sql.append(" WHERE ");
		sql.append(" MEMBERID = "+ memId );
		if(type == 1){
			sql.append(" AND REGISTERSTATUS=1");
		}		
		if(type == 2){
			sql.append(" AND (REGISTERSTATUS=1 OR REGISTERSTATUS=2)");
		}
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				count = rs.getInt("COUNT");
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
		return count;
	}


	@Override
	public MarketCarInfoDto findCarForPad(String licensePlate)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto dto = new MarketCarInfoDto();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" SERIAL, ");
		sql.append("PRICE,");
		sql.append("MEMBERID,");
		sql.append("MILEAGE,");
		sql.append("PHOTO_1,");
		sql.append("PHOTO_2,");
		sql.append("PHOTO_3,");
		sql.append("PHOTO_4,");
		sql.append("PHOTO_5,");
		sql.append("PHOTO_6,");
		sql.append("PHOTO_7,");
		sql.append("PHOTO_8");
		
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" LICENSEPLATE=? ");
		// modify by huangheli at 20150808 start
		//sql.append(" AND REGISTERSTATUS >3  ");
		sql.append(" AND REGISTERSTATUS not in (3,4)  ");
		// modify by huangheli at 20150808 end
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, licensePlate);
			rs = ps.executeQuery();
			while(rs.next()){
				dto.setSerial(rs.getString("SERIAL"));
				dto.setMemberId(rs.getInt("MEMBERID"));
				dto.setMileage(rs.getInt("MILEAGE"));
				dto.setPrice(rs.getInt("PRICE"));
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setPhoto_2(rs.getString("PHOTO_2"));
				dto.setPhoto_3(rs.getString("PHOTO_3"));
				dto.setPhoto_4(rs.getString("PHOTO_4"));
				dto.setPhoto_5(rs.getString("PHOTO_5"));
				dto.setPhoto_6(rs.getString("PHOTO_6"));
				dto.setPhoto_7(rs.getString("PHOTO_7"));
				dto.setPhoto_8(rs.getString("PHOTO_8"));
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return dto;
	}

	public MarketCarInfoDto findCar(String licensePlate,int type) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto dto = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append("DISPLACEMENT,");
		sql.append("GEARBOX,");
		sql.append(" REGDATE,");
		sql.append(" SENDCARDDATE,");
		sql.append(" SERIAL ,");
		sql.append(" PRICE ,");
		sql.append(" MILEAGE ,");
		sql.append(" VENDORID ,");
		sql.append(" BRANDID ,");
		sql.append(" CARSTYLEID ,");
		sql.append(" MEMBERID ,");
		sql.append(" PHOTO_1 ,");
		sql.append(" PHOTO_2 ,");
		sql.append(" PHOTO_3 ,");
		sql.append(" PHOTO_4 ,");
		sql.append(" PHOTO_5 ,");
		sql.append(" PHOTO_6 ,");
		sql.append(" PHOTO_7 ,");
		sql.append(" PHOTO_8 ,");
		sql.append(" CARSCORE ,");
		sql.append(" ATTESTSTATUS,");
		sql.append(" CAROWNER,");
		sql.append(" REGISTERSTATUS,");
		sql.append(" REMARK,");
		sql.append(" COMPANYCONTACTPHONE,");
		sql.append(" COMPANYCONTACTPERSON,");
		sql.append(" YEARCAREFULPERIOD,");
		sql.append(" JQX,");
		sql.append(" REGDATE,");
		sql.append(" COLOR,");
		sql.append(" TEMPLICENSEPLATE,");
		sql.append(" LICENSEPLATE,");
		sql.append(" VIN,");
		sql.append(" ENTERTIME");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		if(type == 1){
			sql.append(" LICENSEPLATE=? ");
		}else{
			sql.append(" TEMPLICENSEPLATE=? ");
		}
		sql.append(" ORDER BY UPDATETIME DESC LIMIT 1");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, licensePlate);
			rs = ps.executeQuery();
			while(rs.next()){
				dto = new MarketCarInfoDto();
				dto.setSerial(rs.getString("SERIAL"));
				dto.setMemberId(rs.getInt("MEMBERID"));
				dto.setMileage(rs.getInt("MILEAGE"));
				dto.setPrice(rs.getInt("PRICE"));
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setPhoto_2(rs.getString("PHOTO_2"));
				dto.setPhoto_3(rs.getString("PHOTO_3"));
				dto.setPhoto_4(rs.getString("PHOTO_4"));
				dto.setPhoto_5(rs.getString("PHOTO_5"));
				dto.setPhoto_6(rs.getString("PHOTO_6"));
				dto.setPhoto_7(rs.getString("PHOTO_7"));
				dto.setPhoto_8(rs.getString("PHOTO_8"));
				dto.setRegDate(rs.getString("REGDATE"));
				dto.setSendCardDate(rs.getString("SENDCARDDATE"));
				dto.setGearbox(rs.getInt("GEARBOX"));
				dto.setVendorId(rs.getString("VENDORID"));
				dto.setBrandId(rs.getString("BRANDID"));
				dto.setCarStyleId(rs.getString("CARSTYLEID"));
				dto.setCarScore(rs.getInt("CARSCORE"));
				dto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				dto.setDisplacement(rs.getInt("DISPLACEMENT"));
				dto.setCarOwner(rs.getString("CAROWNER"));
				dto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				dto.setRemark(rs.getString("REMARK"));
				dto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				dto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				dto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				dto.setJqx(rs.getString("JQX"));
				dto.setRegDate(rs.getString("REGDATE"));
				dto.setColor(rs.getInt("COLOR"));
				dto.setTempLicensePlate(rs.getString("TEMPLICENSEPLATE"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setVin(rs.getString("VIN"));
				dto.setEnterTime(rs.getTimestamp("ENTERTIME"));
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return dto;
	}

	@Override
	public MarketCarInfoDto findCarByLicensePlate(String licensePlate,int type) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto dto = new MarketCarInfoDto();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append("DISPLACEMENT,");
		sql.append("GEARBOX,");
		sql.append(" REGDATE,");
		sql.append(" SENDCARDDATE,");
		sql.append(" SERIAL ,");
		sql.append(" PRICE ,");
		sql.append(" MILEAGE ,");
		sql.append(" VENDORID ,");
		sql.append(" BRANDID ,");
		sql.append(" CARSTYLEID ,");
		sql.append(" MEMBERID ,");
		sql.append(" PHOTO_1 ,");
		sql.append(" PHOTO_2 ,");
		sql.append(" PHOTO_3 ,");
		sql.append(" PHOTO_4 ,");
		sql.append(" PHOTO_5 ,");
		sql.append(" PHOTO_6 ,");
		sql.append(" PHOTO_7 ,");
		sql.append(" PHOTO_8 ,");
		sql.append(" CARSCORE ,");
		sql.append(" ATTESTSTATUS,");
		sql.append(" CAROWNER,");
		sql.append(" REGISTERSTATUS,");
		sql.append(" REMARK,");
		sql.append(" COMPANYCONTACTPHONE,");
		sql.append(" COMPANYCONTACTPERSON,");
		sql.append(" YEARCAREFULPERIOD,");
		sql.append(" JQX,");
		sql.append(" REGDATE,");
		sql.append(" COLOR,");
		sql.append(" TEMPLICENSEPLATE,");
		sql.append(" LICENSEPLATE,");
		sql.append(" VIN");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		if(type == 1){
			sql.append(" LICENSEPLATE=? ");
		}else{
			sql.append(" TEMPLICENSEPLATE=? ");
		}
		

		// modify by huangheli at 20150808 start
		//sql.append(" AND REGISTERSTATUS < 3");
		sql.append(" AND REGISTERSTATUS not in (3,4) ");
		// modify by huangheli at 20150808 end
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, licensePlate);
			rs = ps.executeQuery();
			while(rs.next()){
				dto.setSerial(rs.getString("SERIAL"));
				dto.setMemberId(rs.getInt("MEMBERID"));
				dto.setMileage(rs.getInt("MILEAGE"));
				dto.setPrice(rs.getInt("PRICE"));
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setPhoto_2(rs.getString("PHOTO_2"));
				dto.setPhoto_3(rs.getString("PHOTO_3"));
				dto.setPhoto_4(rs.getString("PHOTO_4"));
				dto.setPhoto_5(rs.getString("PHOTO_5"));
				dto.setPhoto_6(rs.getString("PHOTO_6"));
				dto.setPhoto_7(rs.getString("PHOTO_7"));
				dto.setPhoto_8(rs.getString("PHOTO_8"));
				dto.setRegDate(rs.getString("REGDATE"));
				dto.setSendCardDate(rs.getString("SENDCARDDATE"));
				dto.setGearbox(rs.getInt("GEARBOX"));
				dto.setVendorId(rs.getString("VENDORID"));
				dto.setBrandId(rs.getString("BRANDID"));
				dto.setCarStyleId(rs.getString("CARSTYLEID"));
				dto.setCarScore(rs.getInt("CARSCORE"));
				dto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				dto.setDisplacement(rs.getInt("DISPLACEMENT"));
				dto.setCarOwner(rs.getString("CAROWNER"));
				dto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				dto.setRemark(rs.getString("REMARK"));
				dto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				dto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				dto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				dto.setJqx(rs.getString("JQX"));
				dto.setRegDate(rs.getString("REGDATE"));
				dto.setColor(rs.getInt("COLOR"));
				dto.setTempLicensePlate(rs.getString("TEMPLICENSEPLATE"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setVin(rs.getString("VIN"));
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return dto;
	}

	 
	@Override
	public void updatephotoC(String img1,String img2,String img3,String img4,String serial) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_TRANSFER_ACCEPTED_INFO);
		sql.append(" SET ");
		sql.append(" PHOTO_1=?,");
		sql.append(" PHOTO_2=?, ");
		sql.append(" PHOTO_3=?, ");
		sql.append(" PHOTO_4=? ");
		sql.append(" WHERE ");
		sql.append(" BASICCARID=? ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, img1);
			ps.setString(2, img2);
			ps.setString(3, img3);
			ps.setString(4, img4);
			ps.setString(5, serial);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}		
	}


	

	

	@Override
	public void updateMemberIdBySerial(MarketCarInfoDto dto)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append("MEMBERID=? ");
		// #111
        sql.append(",companyContactPerson=? ");
        sql.append(",companyContactPhone=? ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			
			ps.setInt(1, dto.getMemberId());
            ps.setString(2, dto.getCompanyContactPerson());
            ps.setString(3, dto.getCompanyContactPhone());
			ps.setString(4, dto.getSerial());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}		
	}

	
	@Override
	public void updateNewLicenseBySerial(TransferPersonalCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("UPDATE  ");
			sql.append(TmsTableNames.TMS_TRANSFER_PERSONALCAR_INFO);
			sql.append(" SET  ");
			sql.append(" NEWLICENSEPLATE=?,   ");
			sql.append(" UPDATETIME=SYSDATE() ,  ");
			sql.append(" UPDATEUSERID=?  ");
			sql.append(" WHERE SERIAL =?  ");

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, dto.getNewLicensePlate());
			ps.setInt(2, dto.getUpdateUserId());
			ps.setString(3, dto.getSerial());

			ps.executeUpdate();

		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}			
	}


	@Override
	public void updateNewLicenseBySerial(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("UPDATE  ");
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
			sql.append(" SET  ");
			sql.append(" NEWLICENSEPLATE=LICENSEPLATE,   ");
			sql.append(" UPDATETIME=SYSDATE() ,  ");
			sql.append(" CHGLICENSEPLATETIME=SYSDATE() ,  ");
			sql.append(" LICENSEPLATE=?,  ");
			sql.append(" UPDATEUSERID=?  ");
			sql.append(" WHERE SERIAL =?  ");

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, dto.getNewLicensePlate());
			ps.setInt(2, dto.getUpdateUserId());
			ps.setString(3, dto.getSerial());

			ps.executeUpdate();

		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}			
	}


	@Override
	public void updateLicenseBySerial(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("UPDATE  ");
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
			sql.append(" SET  ");
			sql.append(" LICENSEPLATE=?,   ");
			sql.append(" UPDATETIME=SYSDATE() ,  ");
			sql.append(" UPDATEUSERID=?  ");
			sql.append(" WHERE SERIAL =?  ");

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, dto.getLicensePlate());
			ps.setInt(2, dto.getUpdateUserId());
			ps.setString(3, dto.getSerial());

			ps.executeUpdate();

		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}			
	}


	@Override
	public void deleteCarInfoBySerial(String serial)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("");
			sql.append("DELETE ");
			sql.append("FROM ");
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
			sql.append(" WHERE ");
			sql.append(" SERIAL='"+serial+"' ");
			ps = conn.prepareStatement(sql.toString());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			close(rs, ps);
		}		
	}


	@Override
	public void updateCarName(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("UPDATE  ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET  ");
		sql.append(" CARNAME=?,   ");
		sql.append(" DISPLACEMENT=?,   ");
		sql.append(" GEARBOX=?,   ");
		sql.append(" VENDORID=?,   ");
		sql.append(" BRANDID=?,   ");
		sql.append(" CARSTYLEID=?,   ");
		sql.append(" UPDATETIME=SYSDATE() ,  ");
		sql.append(" UPDATEUSERID=?  ");
		sql.append(" WHERE SERIAL =?  ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, dto.getCarName());
			ps.setInt(2, dto.getDisplacement());
			ps.setInt(3, dto.getGearbox());
			ps.setString(4, dto.getVendorId());
			ps.setString(5, dto.getBrandId());
			ps.setString(6, dto.getCarStyleId());
			ps.setInt(7, dto.getUpdateUserId());
			ps.setString(8, dto.getSerial());
			ps.executeUpdate();
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			close(rs, ps);
		}	
	}


	@Override
	public List findAllImCarName(String startTime, String endTime,int type,int carRidio)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		List sperialCarList = new ArrayList();
		StringBuffer sql = new StringBuffer("");
		if(type == 3){
			sql.append("SELECT BASICCARID,LICENSEPLATE,VIN,MODELCODE,VENDORCODE, ");
		}else{
			sql.append("SELECT SERIAL,LICENSEPLATE,VIN,MODELCODE,VENDORCODE, ");
		}
		if(type == 3){
			sql.append("ACCPETTIME FROM ");
		}else{
			sql.append("INSERTTIME FROM ");
		}
		
		if(type == 1){
			sql.append(TmsTableNames.TMS_TRANSFER_PERSONALCAR_INFO );
		}else if(type == 2){			
			sql.append(TmsTableNames.TMS_MARKET_CAR_INFO );
		}else if(type == 3){
			sql.append(TmsTableNames.TMS_MARKET_CAR_TRANS_INFO );
		}
        sql.append(" WHERE ");	
        if(carRidio == 2){
        	sql.append("CARSTYLEID IS NOT NULL AND CARSTYLEID<>''");
        }else{
        	sql.append("LENGTH(VIN) = 17 AND ");
    		sql.append(" VIN IS NOT NULL AND VIN <> ''");
    		sql.append(" AND ");
    		sql.append(" (CARSTYLEID IS NULL OR CARSTYLEID='')");
        }
		if(type == 3){
			sql.append(" AND DATE_FORMAT(ACCPETTIME,'%Y-%m-%d')>='"+ startTime +"' AND DATE_FORMAT(ACCPETTIME,'%Y-%m-%d')<'"+endTime+"'");
		}else{
			sql.append(" AND DATE_FORMAT(INSERTTIME,'%Y-%m-%d')>='"+ startTime +"' AND DATE_FORMAT(INSERTTIME,'%Y-%m-%d')<'"+endTime+"'");
		}
				
		
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			int i=0;
			String serial = "";
			while(rs.next()){
				if(type == 3){
					serial = rs.getString("BASICCARID");
				}else{
					serial = rs.getString("SERIAL");
				}
				
				sperialCarList.add(serial);
				i++;
			}
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}	
	
		return sperialCarList;
	}

  
	@Override
	public void updateCarInfoForInventory(String serial,int registerStatus,int updateUserId) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" registerStatus="+registerStatus+",");
		sql.append(" UPDATEUSERID=?, ");
		sql.append(" UPDATETIME=SYSDATE()");
		if(registerStatus == 1) sql.append(" ,storageTime=SYSDATE() ");
		else if(registerStatus == 2) sql.append(" ,enterTime=SYSDATE() ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, updateUserId);
			ps.setString(2,serial);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}		
	}
	public void updateChargeStartDateBySerial(String serial,Timestamp chargeStartDate) throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" CHARGESTARTDATE=? ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setTimestamp(1, chargeStartDate);
			ps.setString(2,serial);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}
	
	//type 1:vin 2:licensePlate
	public List<MarketCarInfoDto> findCarList(String condition, int type) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT MARKET.SERIAL,");
		sql.append("MARKET.ID,");
		sql.append("MARKET.CAROWNER,");
		sql.append("MARKET.VIN,");
		sql.append("MARKET.BARCODENUM,");
		sql.append("MARKET.ENGINE,");
		sql.append("MARKET.LICENSEPLATE,");
		sql.append("MARKET.PRICE,");
		sql.append("MARKET.COLOR,");
		sql.append("MARKET.MODELCODE,");
		sql.append("MARKET.VENDORCODE,");
		sql.append("MARKET.REGDATE,");
		sql.append("MARKET.YEARCAREFULPERIOD,");
		sql.append("MARKET.DISPLACEMENT,");
		sql.append("MARKET.JQX,");
		sql.append("MARKET.CARUSE,");
		sql.append("MARKET.CARTYPE,");
		sql.append("MARKET.MILEAGE,");
		sql.append("MARKET.GEARBOX,");
		sql.append("MARKET.SENDCARDDATE,");
		sql.append("MARKET.CARDTYPE,");
		sql.append("MARKET.COUNTRYSTYLE,");
		sql.append("MARKET.REGISTERCARDNO,");
		sql.append("MARKET.COMPANYCONTACTPERSON,");
		sql.append("MARKET.COMPANYCONTACTPHONE,");
		sql.append("MARKET.CAROWNERIDCARDNO,");
		sql.append("MARKET.CARSTYLEID,");
		sql.append("MARKET.BRANDID,");
		sql.append("MARKET.MEMBERID,");
		sql.append("MARKET.FUELTYPE,");
		sql.append("MARKET.LOADQUALITY,");
		sql.append("MARKET.PASSENGER,");
		sql.append("MARKET.OWNERPHONE,");
		sql.append("MARKET.OWNERADDRESS,");
		sql.append("MARKET.ATTRIBUTE,");
		sql.append("MARKET.OWNERTYPE,");
		sql.append("MARKET.OWNERORGNO,");
		sql.append("MARKET.UPDATETIME,");
		sql.append("MARKET.UPDATEUSERID, ");
		sql.append("MARKET.PHOTO_1, ");
		sql.append("MARKET.PHOTO_2, ");
		sql.append("MARKET.PHOTO_3, ");
		sql.append("MARKET.PHOTO_4, ");
		sql.append("MARKET.PHOTO_5, ");
		sql.append("MARKET.PHOTO_6, ");
		sql.append("MARKET.PHOTO_7, ");
		sql.append("MARKET.PHOTO_8, ");
		sql.append("MARKET.REGISTERSTATUS, ");
		sql.append("MARKET.ENTRYSTATUS, ");	
		sql.append("MARKET.INSERTUSERID, ");
		sql.append("MARKET.VENDORID, ");
		sql.append("MARKET.STATUS, ");
		sql.append("MARKET.CARSCORE, ");
		sql.append("MARKET.ATTESTSTATUS, ");
		sql.append("MARKET.STORAGETIME, ");
		sql.append("MARKET.CARNAME, ");
		sql.append("MARKET.INSERTTIME, ");
		sql.append("MARKET.TEMPLICENSEPLATE, ");
		sql.append("MARKET.STORAGETIME, ");
		sql.append("MARKET.ENTERTIME, ");
		sql.append("MEMBER.SHORTNAME, ");
		sql.append("MEMBER.CARPORT, "); //add by mufeiyu
		sql.append("MEMBER.USEDCARPORT, "); //add by mufeiyu
		sql.append("MARKET.INSERTUSERID, ");
		sql.append("MARKET.REMARK, ");
		sql.append("MARKET.TMPSTORAGETIME, ");
		sql.append("MARKET.TMPENTERTIME ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" MARKET");
		sql.append(" LEFT JOIN  ");
		sql.append(TmsTableNames.TMS_MEMBER);
		sql.append(" MEMBER ");
		sql.append(" ON MEMBER.MEMBERID=MARKET.MEMBERID");
		sql.append(" WHERE " );
		sql.append(" 1=1");
		if(type == 1) {	
		   sql.append(" AND MARKET.VIN LIKE '%"+condition+"'  ");
		   sql.append(" AND MARKET.REGISTERSTATUS not in (3,4) ");
		}else if(type == 2){
		   sql.append(" AND MARKET.LICENSEPLATE LIKE '%"+condition+"'  ");
		   sql.append(" AND MARKET.REGISTERSTATUS not in (3,4) ");
		}else if(type == 3){
			sql.append(" AND MARKET.ID='"+condition+"'  ");
		}else if(type == 4){
			sql.append(" AND MARKET.SERIAL='"+condition+"'  ");
		}
		
		sql.append(" order by UPDATETIME desc ");
		try {
			ps = conn.prepareStatement(sql.toString());		
			//ps.setString(1, serial);			
			rs = ps.executeQuery();
			List<MarketCarInfoDto> r = new ArrayList<MarketCarInfoDto>();
			while (rs.next()) {		
				MarketCarInfoDto marketCarInfoDto  = new MarketCarInfoDto();
				marketCarInfoDto.setBarCodeNum(rs.getInt("BARCODENUM"));
				marketCarInfoDto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				marketCarInfoDto.setTempLicensePlate(rs.getString("TEMPLICENSEPLATE"));
				marketCarInfoDto.setStorageTime(rs.getTimestamp("STORAGETIME"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setMemberName(rs.getString("SHORTNAME"));
				marketCarInfoDto.setCarPort(rs.getInt("CARPORT")); //add by mufeiyu
				marketCarInfoDto.setUsedCarPort(rs.getInt("USEDCARPORT")); //add by mufeiyu
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setStatus(rs.getInt("STATUS"));
				marketCarInfoDto.setCarScore(rs.getInt("CARSCORE"));
				marketCarInfoDto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				marketCarInfoDto.setCarName(rs.getString("CARNAME"));
				marketCarInfoDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				marketCarInfoDto.setRemark(rs.getString("REMARK"));
				marketCarInfoDto.setTmpStorageTime(rs.getTimestamp("TMPSTORAGETIME"));
				marketCarInfoDto.setTmpEnterTime(rs.getTimestamp("TMPENTERTIME"));
				r.add(marketCarInfoDto);
				}
			
			return r;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
	
// add by mufeiyu start
	/**
	 * 对车架号是否已经使用进行check
	 * @param vin
	 * @return
	 */
	public String vinCheck(String vin) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		String memberId = "";
		
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ");
		sql.append("MEMBERID ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" REGISTERSTATUS not in (3,4) ");
		sql.append(" AND VIN = ?");
		
		try {
			ps = conn.prepareStatement(sql.toString());	
			ps.setString(1, vin);	
			rs = ps.executeQuery();
			while (rs.next()) {
				memberId = rs.getString("MEMBERID");
			}

			return memberId;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
	
	/**
	 * 对车架号是否已经使用进行check 不为“4：存档”
	 * @param vin
	 * @return
	 */
	public String vinCheckNotKeep(String vin) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		String memberId = "";
		
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ");
		sql.append("MEMBERID ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" REGISTERSTATUS <> 4 ");
		sql.append(" AND VIN = ?");
		
		try {
			ps = conn.prepareStatement(sql.toString());	
			ps.setString(1, vin);	
			rs = ps.executeQuery();
			while (rs.next()) {
				memberId = rs.getString("MEMBERID");
			}

			return memberId;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
	
	//type 1:vin 2:licensePlate  车辆库存状态（不为  4：存档）到库存表中查询
	public List<MarketCarInfoDto> findCarListNotKeep(String condition, int type) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT MARKET.SERIAL,");
		sql.append("MARKET.ID,");
		sql.append("MARKET.CAROWNER,");
		sql.append("MARKET.VIN,");
		sql.append("MARKET.BARCODENUM,");
		sql.append("MARKET.ENGINE,");
		sql.append("MARKET.LICENSEPLATE,");
		sql.append("MARKET.PRICE,");
		sql.append("MARKET.COLOR,");
		sql.append("MARKET.MODELCODE,");
		sql.append("MARKET.VENDORCODE,");
		sql.append("MARKET.REGDATE,");
		sql.append("MARKET.YEARCAREFULPERIOD,");
		sql.append("MARKET.DISPLACEMENT,");
		sql.append("MARKET.JQX,");
		sql.append("MARKET.CARUSE,");
		sql.append("MARKET.INTERNALSCORE,");
		sql.append("MARKET.EXTERNALSCORE,");
		sql.append("MARKET.DETECTREMARK,");
		sql.append("MARKET.CARTYPE,");
		sql.append("MARKET.MILEAGE,");
		sql.append("MARKET.GEARBOX,");
		sql.append("MARKET.SENDCARDDATE,");
		sql.append("MARKET.CARDTYPE,");
		sql.append("MARKET.COUNTRYSTYLE,");
		sql.append("MARKET.REGISTERCARDNO,");
		sql.append("MARKET.COMPANYCONTACTPERSON,");
		sql.append("MARKET.COMPANYCONTACTPHONE,");
		sql.append("MARKET.CAROWNERIDCARDNO,");
		sql.append("MARKET.CARSTYLEID,");
		sql.append("MARKET.BRANDID,");
		sql.append("MARKET.MEMBERID,");
		sql.append("MARKET.FUELTYPE,");
		sql.append("MARKET.LOADQUALITY,");
		sql.append("MARKET.PASSENGER,");
		sql.append("MARKET.OWNERPHONE,");
		sql.append("MARKET.OWNERADDRESS,");
		sql.append("MARKET.ATTRIBUTE,");
		sql.append("MARKET.OWNERTYPE,");
		sql.append("MARKET.OWNERORGNO,");
		sql.append("MARKET.UPDATETIME,");
		sql.append("MARKET.UPDATEUSERID, ");
		sql.append("MARKET.PHOTO_1, ");
		sql.append("MARKET.PHOTO_2, ");
		sql.append("MARKET.PHOTO_3, ");
		sql.append("MARKET.PHOTO_4, ");
		sql.append("MARKET.PHOTO_5, ");
		sql.append("MARKET.PHOTO_6, ");
		sql.append("MARKET.PHOTO_7, ");
		sql.append("MARKET.PHOTO_8, ");
		sql.append("MARKET.REGISTERSTATUS, ");
		sql.append("MARKET.ENTRYSTATUS, ");	
		sql.append("MARKET.INSERTUSERID, ");
		sql.append("MARKET.VENDORID, ");
		sql.append("MARKET.STATUS, ");
		sql.append("MARKET.CARSCORE, ");
		sql.append("MARKET.ATTESTSTATUS, ");
		sql.append("MARKET.STORAGETIME, ");
		sql.append("MARKET.CARNAME, ");
		sql.append("MARKET.ISMATCH, ");
		sql.append("MARKET.INSERTTIME, ");
		sql.append("MARKET.TEMPLICENSEPLATE, ");
		sql.append("MARKET.STORAGETIME, ");
		sql.append("MARKET.ENTERTIME, ");
		sql.append("MEMBER.SHORTNAME, ");
		sql.append("MEMBER.CARPORT, "); 
		sql.append("MEMBER.USEDCARPORT, "); 
		sql.append("MARKET.INSERTUSERID, ");
		sql.append("MARKET.REMARK, ");
		sql.append("MARKET.CONFIGKEY ");
		sql.append(" , MARKET.isShelve ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" MARKET");
		sql.append(" LEFT JOIN  ");
		sql.append(TmsTableNames.TMS_MEMBER);
		sql.append(" MEMBER ");
		sql.append(" ON MEMBER.MEMBERID=MARKET.MEMBERID");
		sql.append(" WHERE " );
		sql.append(" 1=1");
		if(type == 1) {	
		   sql.append(" AND MARKET.VIN LIKE '%"+condition+"'  ");
		   sql.append(" AND MARKET.REGISTERSTATUS <> 4 ");
		}else if(type == 2){
		   sql.append(" AND MARKET.LICENSEPLATE LIKE '%"+condition+"'  ");
		   sql.append(" AND MARKET.REGISTERSTATUS <> 4 ");
		}else if(type == 3){
			sql.append(" AND MARKET.ID='"+condition+"'  ");
		}
		
		sql.append(" order by UPDATETIME desc ");
		try {
			ps = conn.prepareStatement(sql.toString());		
			//ps.setString(1, serial);			
			rs = ps.executeQuery();
			List<MarketCarInfoDto> r = new ArrayList<MarketCarInfoDto>();
			while (rs.next()) {		
				MarketCarInfoDto marketCarInfoDto  = new MarketCarInfoDto();
				marketCarInfoDto.setBarCodeNum(rs.getInt("BARCODENUM"));
				marketCarInfoDto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				marketCarInfoDto.setTempLicensePlate(rs.getString("TEMPLICENSEPLATE"));
				marketCarInfoDto.setStorageTime(rs.getTimestamp("STORAGETIME"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setMemberName(rs.getString("SHORTNAME"));
				marketCarInfoDto.setCarPort(rs.getInt("CARPORT"));
				marketCarInfoDto.setUsedCarPort(rs.getInt("USEDCARPORT"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setStatus(rs.getInt("STATUS"));
				marketCarInfoDto.setCarScore(rs.getInt("CARSCORE"));
				marketCarInfoDto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				marketCarInfoDto.setCarName(rs.getString("CARNAME"));
				marketCarInfoDto.setIsMatch(rs.getInt("ISMATCH"));
				marketCarInfoDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				marketCarInfoDto.setRemark(rs.getString("REMARK"));
				marketCarInfoDto.setConfigKey(rs.getString("CONFIGKEY"));
				marketCarInfoDto.setDetectRemark(rs.getString("DETECTREMARK"));
				marketCarInfoDto.setInternalScore(rs.getString("INTERNALSCORE"));
				marketCarInfoDto.setExternalScore(rs.getString("EXTERNALSCORE"));
				marketCarInfoDto.setIsShelve(rs.getInt("isShelve"));
				r.add(marketCarInfoDto);
				}
			
			return r;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}

	//type 1:vin 2:licensePlate  车辆库存状态（3：取消）到库存表中查询
	public List<MarketCarInfoDto> findCarListIsCancel(String condition, int type) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT MARKET.SERIAL,");
		sql.append("MARKET.ID,");
		sql.append("MARKET.CAROWNER,");
		sql.append("MARKET.VIN,");
		sql.append("MARKET.BARCODENUM,");
		sql.append("MARKET.ENGINE,");
		sql.append("MARKET.LICENSEPLATE,");
		sql.append("MARKET.PRICE,");
		sql.append("MARKET.COLOR,");
		sql.append("MARKET.MODELCODE,");
		sql.append("MARKET.VENDORCODE,");
		sql.append("MARKET.REGDATE,");
		sql.append("MARKET.YEARCAREFULPERIOD,");
		sql.append("MARKET.DISPLACEMENT,");
		sql.append("MARKET.JQX,");
		sql.append("MARKET.CARUSE,");
		sql.append("MARKET.CARTYPE,");
		sql.append("MARKET.MILEAGE,");
		sql.append("MARKET.GEARBOX,");
		sql.append("MARKET.SENDCARDDATE,");
		sql.append("MARKET.CARDTYPE,");
		sql.append("MARKET.COUNTRYSTYLE,");
		sql.append("MARKET.REGISTERCARDNO,");
		sql.append("MARKET.COMPANYCONTACTPERSON,");
		sql.append("MARKET.COMPANYCONTACTPHONE,");
		sql.append("MARKET.CAROWNERIDCARDNO,");
		sql.append("MARKET.CARSTYLEID,");
		sql.append("MARKET.BRANDID,");
		sql.append("MARKET.MEMBERID,");
		sql.append("MARKET.FUELTYPE,");
		sql.append("MARKET.LOADQUALITY,");
		sql.append("MARKET.PASSENGER,");
		sql.append("MARKET.OWNERPHONE,");
		sql.append("MARKET.OWNERADDRESS,");
		sql.append("MARKET.ATTRIBUTE,");
		sql.append("MARKET.OWNERTYPE,");
		sql.append("MARKET.OWNERORGNO,");
		sql.append("MARKET.UPDATETIME,");
		sql.append("MARKET.UPDATEUSERID, ");
		sql.append("MARKET.PHOTO_1, ");
		sql.append("MARKET.PHOTO_2, ");
		sql.append("MARKET.PHOTO_3, ");
		sql.append("MARKET.PHOTO_4, ");
		sql.append("MARKET.PHOTO_5, ");
		sql.append("MARKET.PHOTO_6, ");
		sql.append("MARKET.PHOTO_7, ");
		sql.append("MARKET.PHOTO_8, ");
		sql.append("MARKET.REGISTERSTATUS, ");
		sql.append("MARKET.ENTRYSTATUS, ");	
		sql.append("MARKET.INSERTUSERID, ");
		sql.append("MARKET.VENDORID, ");
		sql.append("MARKET.STATUS, ");
		sql.append("MARKET.CARSCORE, ");
		sql.append("MARKET.ATTESTSTATUS, ");
		sql.append("MARKET.STORAGETIME, ");
		sql.append("MARKET.CARNAME, ");
		sql.append("MARKET.ISMATCH, ");
		sql.append("MARKET.ISSHELVE, ");
		sql.append("MARKET.INSERTTIME, ");
		sql.append("MARKET.TEMPLICENSEPLATE, ");
		sql.append("MARKET.STORAGETIME, ");
		sql.append("MARKET.ENTERTIME, ");
		sql.append("MEMBER.SHORTNAME, ");
		sql.append("MEMBER.REALNAMEPY, ");
		sql.append("MEMBER.CARPORT, "); 
		sql.append("MEMBER.USEDCARPORT, "); 
		sql.append("MARKET.INSERTUSERID, ");
		sql.append("MARKET.REMARK, ");
		sql.append("MARKET.CATCLASS ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" MARKET");
		sql.append(" LEFT JOIN  ");
		sql.append(TmsTableNames.TMS_MEMBER);
		sql.append(" MEMBER ");
		sql.append(" ON MEMBER.MEMBERID=MARKET.MEMBERID");
		sql.append(" WHERE " );
		sql.append(" 1=1");
		if(type == 1) {	
		   sql.append(" AND MARKET.VIN LIKE '%"+condition+"'  ");
		   sql.append(" AND MARKET.REGISTERSTATUS = 3 ");
		}else if(type == 2){
		   sql.append(" AND MARKET.LICENSEPLATE LIKE '%"+condition+"'  ");
		   sql.append(" AND MARKET.REGISTERSTATUS = 3 ");
		}else if(type == 3){
			sql.append(" AND MARKET.ID='"+condition+"'  ");
		}
		
		sql.append(" order by UPDATETIME desc ");
		try {
			ps = conn.prepareStatement(sql.toString());		
			//ps.setString(1, serial);			
			rs = ps.executeQuery();
			List<MarketCarInfoDto> r = new ArrayList<MarketCarInfoDto>();
			while (rs.next()) {		
				MarketCarInfoDto marketCarInfoDto  = new MarketCarInfoDto();
				marketCarInfoDto.setBarCodeNum(rs.getInt("BARCODENUM"));
				marketCarInfoDto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				marketCarInfoDto.setTempLicensePlate(rs.getString("TEMPLICENSEPLATE"));
				marketCarInfoDto.setStorageTime(rs.getTimestamp("STORAGETIME"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setMemberName(rs.getString("SHORTNAME")+"["+rs.getString("REALNAMEPY")+"]");
				marketCarInfoDto.setCarPort(rs.getInt("CARPORT"));
				marketCarInfoDto.setUsedCarPort(rs.getInt("USEDCARPORT"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setStatus(rs.getInt("STATUS"));
				marketCarInfoDto.setCarScore(rs.getInt("CARSCORE"));
				marketCarInfoDto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				marketCarInfoDto.setCarName(rs.getString("CARNAME"));
				marketCarInfoDto.setIsMatch(rs.getInt("ISMATCH"));
				marketCarInfoDto.setIsShelve(rs.getInt("ISSHELVE"));
				marketCarInfoDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				marketCarInfoDto.setRemark(rs.getString("REMARK"));
				marketCarInfoDto.setCatClass(rs.getInt("CATCLASS"));
				r.add(marketCarInfoDto);
				}
			
			return r;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
// add by mufeiyu e n d

	@Override
	public MarketCarInfoDto findCarByLicensePlate(String tempLicensePlate, String licensePlate) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT SERIAL,");
		sql.append("ID,");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("LICENSEPLATE,");
		sql.append("PRICE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("MEMBERID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("ATTRIBUTE,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("UPDATETIME,");
		sql.append("UPDATEUSERID, ");
		sql.append("PHOTO_1, ");
		sql.append("PHOTO_2, ");
		sql.append("PHOTO_3, ");
		sql.append("PHOTO_4, ");
		sql.append("PHOTO_5, ");
		sql.append("PHOTO_6, ");
		sql.append("PHOTO_7, ");
		sql.append("PHOTO_8, ");
		sql.append("REGISTERSTATUS, ");
		sql.append("ENTRYSTATUS, ");	
		sql.append("INSERTUSERID, ");
		sql.append("VENDORID, ");
		sql.append("STATUS, ");
		sql.append("CARSCORE, ");
		sql.append("ATTESTSTATUS, ");
		sql.append("STORAGETIME, ");
		sql.append("CARNAME, ");
		sql.append("INSERTTIME, ");
		sql.append("TEMPLICENSEPLATE, ");
		sql.append("STORAGETIME, ");
		sql.append("ENTERTIME, ");
		sql.append("INSERTUSERID ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		if(!StringUtil.isNullOrBlank(tempLicensePlate))
		{	
		sql.append(" TEMPLICENSEPLATE='"+tempLicensePlate+"'  ");
		}
		if(!StringUtil.isNullOrBlank(tempLicensePlate) && !StringUtil.isNullOrBlank(licensePlate))
		{
			sql.append(" AND ");
		}
		if(!StringUtil.isNullOrBlank(licensePlate))
		{
			sql.append(" LICENSEPLATE = '"+licensePlate+"'  ");//车牌号
		}
		sql.append(" AND REGISTERSTATUS not in (3,4) ");
		sql.append(" order by UPDATETIME desc limit 1 ");
		try {
			ps = conn.prepareStatement(sql.toString());		
			//ps.setString(1, serial);			
			rs = ps.executeQuery();
		
			while (rs.next()) {		
				marketCarInfoDto = new MarketCarInfoDto();
				marketCarInfoDto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				marketCarInfoDto.setTempLicensePlate(rs.getString("TEMPLICENSEPLATE"));
				marketCarInfoDto.setStorageTime(rs.getTimestamp("STORAGETIME"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setStatus(rs.getInt("STATUS"));
				marketCarInfoDto.setCarScore(rs.getInt("CARSCORE"));
				marketCarInfoDto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				marketCarInfoDto.setCarName(rs.getString("CARNAME"));
				marketCarInfoDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				}
			
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}


	// add by huangheli at 20150803 start
	// 如果出现多条就显示updatetime最新那条
	@Override
	public MarketCarInfoDto findCarBySerialLicensePlate(String serial,String licensePlate) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT SERIAL,");
		sql.append("ID,");
		sql.append("CAROWNER,");
		sql.append("VIN,");
		sql.append("ENGINE,");
		sql.append("LICENSEPLATE,");
		sql.append("PRICE,");
		sql.append("COLOR,");
		sql.append("MODELCODE,");
		sql.append("VENDORCODE,");
		sql.append("REGDATE,");
		sql.append("YEARCAREFULPERIOD,");
		sql.append("DISPLACEMENT,");
		sql.append("JQX,");
		sql.append("CARUSE,");
		sql.append("CARTYPE,");
		sql.append("MILEAGE,");
		sql.append("GEARBOX,");
		sql.append("SENDCARDDATE,");
		sql.append("CARDTYPE,");
		sql.append("COUNTRYSTYLE,");
		sql.append("REGISTERCARDNO,");
		sql.append("COMPANYCONTACTPERSON,");
		sql.append("COMPANYCONTACTPHONE,");
		sql.append("CAROWNERIDCARDNO,");
		sql.append("CARSTYLEID,");
		sql.append("BRANDID,");
		sql.append("MEMBERID,");
		sql.append("FUELTYPE,");
		sql.append("LOADQUALITY,");
		sql.append("PASSENGER,");
		sql.append("OWNERPHONE,");
		sql.append("OWNERADDRESS,");
		sql.append("ATTRIBUTE,");
		sql.append("OWNERTYPE,");
		sql.append("OWNERORGNO,");
		sql.append("UPDATETIME,");
		sql.append("UPDATEUSERID, ");
		sql.append("PHOTO_1, ");
		sql.append("PHOTO_2, ");
		sql.append("PHOTO_3, ");
		sql.append("PHOTO_4, ");
		sql.append("PHOTO_5, ");
		sql.append("PHOTO_6, ");
		sql.append("PHOTO_7, ");
		sql.append("PHOTO_8, ");
		sql.append("REGISTERSTATUS, ");
		sql.append("ENTRYSTATUS, ");	
		sql.append("INSERTUSERID, ");
		sql.append("VENDORID, ");
		sql.append("STATUS, ");
		sql.append("CARSCORE, ");
		sql.append("ATTESTSTATUS, ");
		sql.append("STORAGETIME, ");
		sql.append("CARNAME, ");
		sql.append("INSERTTIME, ");
		sql.append("INSERTUSERID ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		if(!StringUtil.isNullOrBlank(serial))
		{	
		sql.append(" SERIAL='"+serial+"'  ");
		}
		if(!StringUtil.isNullOrBlank(serial) && !StringUtil.isNullOrBlank(licensePlate))
		{
			sql.append(" AND ");
		}
		if(!StringUtil.isNullOrBlank(licensePlate))
		{
			sql.append(" LICENSEPLATE = '"+licensePlate+"'  ");//车牌号
		}
		sql.append(" AND REGISTERSTATUS not in (3,4) ");
		sql.append(" order by UPDATETIME desc limit 1 ");
		try {
			ps = conn.prepareStatement(sql.toString());		
			//ps.setString(1, serial);			
			rs = ps.executeQuery();
		
			while (rs.next()) {		
				marketCarInfoDto = new MarketCarInfoDto();
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setSerial(rs.getString("SERIAL"));
				marketCarInfoDto.setVin(rs.getString("VIN"));
				marketCarInfoDto.setEngine(rs.getString("ENGINE"));
				marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setPrice(rs.getInt("PRICE"));
				marketCarInfoDto.setColor(rs.getInt("COLOR"));
				marketCarInfoDto.setModelCode(rs.getString("MODELCODE"));
				marketCarInfoDto.setVendorCode(rs.getString("VENDORCODE"));
				marketCarInfoDto.setRegDate(rs.getString("REGDATE"));
				marketCarInfoDto.setYearCarefulPeriod(rs.getString("YEARCAREFULPERIOD"));
				marketCarInfoDto.setDisplacement(rs.getInt("DISPLACEMENT"));
				marketCarInfoDto.setJqx(rs.getString("JQX"));
				marketCarInfoDto.setCarUse(rs.getInt("CARUSE"));
				marketCarInfoDto.setCarType(rs.getInt("CARTYPE"));
				marketCarInfoDto.setMileage(rs.getInt("MILEAGE"));
				marketCarInfoDto.setGearbox(rs.getInt("GEARBOX"));
				marketCarInfoDto.setSendCardDate(rs.getString("SENDCARDDATE"));
				marketCarInfoDto.setCardType(rs.getInt("CARDTYPE"));
				marketCarInfoDto.setCountryStyle(rs.getInt("COUNTRYSTYLE"));
				marketCarInfoDto.setRegisterCardNo(rs.getString("REGISTERCARDNO"));
				marketCarInfoDto.setCompanyContactPerson(rs.getString("COMPANYCONTACTPERSON"));
				marketCarInfoDto.setCompanyContactPhone(rs.getString("COMPANYCONTACTPHONE"));
				marketCarInfoDto.setCarOwnerIdCardNo(rs.getString("CAROWNERIDCARDNO"));
				marketCarInfoDto.setCarStyleId(rs.getString("CARSTYLEID"));
				marketCarInfoDto.setBrandId(rs.getString("BRANDID"));
				marketCarInfoDto.setMemberId(rs.getInt("MEMBERID"));
				marketCarInfoDto.setFuelType(rs.getInt("FUELTYPE"));
				marketCarInfoDto.setLoadquality(rs.getInt("LOADQUALITY"));
				marketCarInfoDto.setPassenger(rs.getInt("PASSENGER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));				
				marketCarInfoDto.setAttribute(rs.getInt("ATTRIBUTE"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				marketCarInfoDto.setOwnerOrgNo(rs.getString("OWNERORGNO"));
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserId(rs.getInt("UPDATEUSERID"));
				marketCarInfoDto.setPhoto_1(rs.getString("PHOTO_1"));
				marketCarInfoDto.setPhoto_2(rs.getString("PHOTO_2"));
				marketCarInfoDto.setPhoto_3(rs.getString("PHOTO_3"));
				marketCarInfoDto.setPhoto_4(rs.getString("PHOTO_4"));
				marketCarInfoDto.setPhoto_5(rs.getString("PHOTO_5"));
				marketCarInfoDto.setPhoto_6(rs.getString("PHOTO_6"));
				marketCarInfoDto.setPhoto_7(rs.getString("PHOTO_7"));
				marketCarInfoDto.setPhoto_8(rs.getString("PHOTO_8"));
				marketCarInfoDto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				marketCarInfoDto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				marketCarInfoDto.setVendorId(rs.getString("VENDORID"));
				marketCarInfoDto.setStatus(rs.getInt("STATUS"));
				marketCarInfoDto.setCarScore(rs.getInt("CARSCORE"));
				marketCarInfoDto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				marketCarInfoDto.setCarName(rs.getString("CARNAME"));
				marketCarInfoDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				marketCarInfoDto.setInsertUserId(rs.getInt("INSERTUSERID"));
				}
			
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		
	}
	
	@Override
	public void updatePendingliftStatus(MarketCarInfoDto dto,int type)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");

		sql.append(" REGISTERSTATUS=?, ");
		sql.append(" UPDATEUSERID=?, ");
		sql.append(" UPDATETIME=SYSDATE() ");
		
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, type);
			ps.setInt(2, dto.getUpdateUserId());
			ps.setString(3, dto.getSerial());

			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
	}
	// add by huangheli at 20150803 end


	@Override
	public void updateCarInfoForBarCodeNum(String serial,int barCodeNum) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" BARCODENUM=?, ");
		sql.append(" TMPSTORAGETIME=?,");
		sql.append(" TMPENTERTIME=?");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, barCodeNum);
			ps.setTimestamp(2, null);
			ps.setTimestamp(3, null);
			ps.setString(4,serial);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
	}
	
	
	
	/**
	 * 根据新车牌号码判断是否有相同车牌号码 并且状态不为过期的车辆
	 * */
	@Override
	public MarketCarInfoDto findCarFlagByNewLicensePlate(String newLicensePlate)
			throws TmsDaoException {
		MarketCarInfoDto dto = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" serial, ");
		sql.append(" REGISTERSTATUS  ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" newLicensePlate=? ");
		// modify by huangheli at 20150808 start
		//sql.append(" AND REGISTERSTATUS < 3");
		sql.append(" AND REGISTERSTATUS not in (3,4) ");
		// modify by huangheli at 20150808 end
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, newLicensePlate);
			rs = ps.executeQuery();
			if(rs.next()) {
				dto = new MarketCarInfoDto();
				dto.setSerial(rs.getString("serial"));
				dto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
			}
			return dto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
	}

	
	@Override
	public void updateRegisterStatus(String serial, int registerStatus,int updateUserId) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" registerStatus=?, ");
		sql.append(" UPDATEUSERID=?, ");
		sql.append(" UPDATETIME=SYSDATE() ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, registerStatus);
			ps.setInt(2, updateUserId);
			ps.setString(3,serial);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
	}
	
	@Override
	public void updateMarketCarInfo(String serial, int status, int updateUserId) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" status=?, ");
		sql.append(" UPDATEUSERID=?, ");
		sql.append(" UPDATETIME=SYSDATE() ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, status);
			ps.setInt(2, updateUserId);
			ps.setString(3,serial);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}
	
	@Override
	public void updateTmpLicensePlate(String licensePlate, int isUsed) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_TEMP_LICENSEPLATE);
		sql.append(" SET ");
		sql.append(" ISUSE=? ");
		sql.append(" WHERE ");
		sql.append(" LICENSEPLATE=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, isUsed);
			ps.setString(2, licensePlate);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}

	@Override
	public List<MarketCarInfoDto> getMarCarInfo(String memberId, String vin) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> list = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append(" id AS ID,");
		sql.append(" serial AS SERIAL, ");
		sql.append(" licensePlate AS LICENSEPLATE,");
		sql.append(" carName AS CARNAME,");
		sql.append(" photo_1 AS PHOTO_1,");
		sql.append(" storageTime AS STORAGETIME,");
		sql.append(" enterTime AS ENTERTIME,");
		sql.append(" insertTime AS INSERTTIME ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" memberId=" + memberId);
		sql.append(" AND vin = '" + vin+"'");
		sql.append(" ORDER BY INSERTTIME DESC");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				dto.setSerial(rs.getString("SERIAL"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setCarName(rs.getString("CARNAME"));
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setStorageTime(rs.getTimestamp("STORAGETIME"));
				dto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				dto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				list.add(dto);
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}	
		return list;
	}

	@Override
	public List<MarketCarInfoDto> getCarInfo(String memberId, String carScore) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> list = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append(" id AS ID,");
		sql.append(" serial AS SERIAL, ");
		sql.append(" licensePlate AS LICENSEPLATE,");
		sql.append(" carName AS CARNAME,");
		sql.append(" photo_1 AS PHOTO_1,");
		sql.append(" storageTime AS STORAGETIME,");
		sql.append(" enterTime AS ENTERTIME,");
		sql.append(" insertTime AS INSERTTIME ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" memberId=" + memberId);
//		sql.append(" AND carScore=" + carScore);
		sql.append(" AND registerStatus = 1");
		sql.append(" ORDER BY INSERTTIME DESC");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				dto.setSerial(rs.getString("SERIAL"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setCarName(rs.getString("CARNAME"));
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setStorageTime(rs.getTimestamp("STORAGETIME"));
				dto.setEnterTime(rs.getTimestamp("ENTERTIME"));
				dto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				list.add(dto);
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}	
		return list;
		
	}


	@Override
	public List<MarketCarGateInfoDto> findInoutResult(String serial) throws TmsDaoException {
		
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarGateInfoDto> list = new ArrayList<MarketCarGateInfoDto>();
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append("GATEINFO.THREADTYPE AS THREADTYPE, ");
		sql.append("GATEINFO.GATETYPE AS GATETYPE, ");
		sql.append("GATEINFO.CARPHOTO AS CARPHOTO, ");
		sql.append("GATEINFO.CHECKFLAG AS CHECKFLAG, ");
		sql.append("GATEINFO.LOCATEDIP AS LOCATEDIP, ");
		sql.append("GATEINFO.THREADSTATUS AS THREADSTATUS, ");
		sql.append("GATEINFO.SERIAL AS SERIAL, ");
		sql.append("GATEINFO.LICENSEPLATE AS LICENSEPLATE, ");
		sql.append("GATEINFO.INSERTTIME  AS INSERTTIME");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_GATEINFO);
		sql.append(" AS GATEINFO  ");		
		sql.append(" WHERE 1=1");
		sql.append(" AND GATEINFO.serial = ? ");
		sql.append(" ORDER BY GATEINFO.insertTime DESC LIMIT 10");
		
		MarketCarGateInfoDto carDto = null;
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, serial);
			rs = ps.executeQuery();
			int i=0;
			while (rs.next()){
				carDto = new MarketCarGateInfoDto();
				carDto.setSerial(rs.getString("SERIAL"));
				carDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				carDto.setLocatedIP(rs.getString("LOCATEDIP"));
				carDto.setInsertTime(rs.getTimestamp("INSERTTIME"));
				carDto.setThreadType(rs.getInt("THREADTYPE"));
				carDto.setGateType(rs.getString("GATETYPE"));
				carDto.setCarPhoto(rs.getString("CARPHOTO"));
				carDto.setThreadStatus(rs.getInt("THREADSTATUS"));
				carDto.setCheckFlag(rs.getInt("CHECKFLAG"));
				if(i%2 == 0){
					carDto.setCssFlag(1);
				}else{
					carDto.setCssFlag(2);
				}
				int num = (i+1)+(getPageNo()-1)*30;
				carDto.setNum(num);
				list.add(carDto);
				i++;
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}	
		
		return list;
	}
	
	/**
	 * 判断输入的车架号是否已经被登记过
	 * */
	@Override
	public boolean isExistMarketCarByVin(String vin)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		boolean flag = false;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" VIN=? ");
		sql.append(" AND REGISTERSTATUS not in (3,4) ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, vin);
			rs = ps.executeQuery();
			while(rs.next()){
				flag =true;
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return flag;
	}
	/**
	 * 插入库存车辆特殊处理数据
	 * */
	public void insertCarHandleInfo(MarketCarHandleInfoDto dto)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("INSERT INTO ");
			sql.append(TmsTableNames.TMS_MARKET_CAR_HANDLEINFO);
			sql.append("(");
			sql.append("SERIAL, ");
			sql.append("HANDLETYPE, ");
			sql.append("ISPUSH, ");
			sql.append("PUSHCONTENT,");
			sql.append("PHOTO,");
			sql.append("UPDATEUSERID, ");
			sql.append("REMARK, ");
			sql.append("UPDATETIME ");			
			sql.append("  ) VALUES ( ");
			sql.append(" ?,?,?,?,?,?,?,? )");

			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, dto.getSerial());
			ps.setInt(2, dto.getHandleType());
			ps.setInt(3, dto.getIsPush());
			ps.setString(4, dto.getPushContent());
			ps.setString(5, dto.getAcceptorImage());
			ps.setInt(6, dto.getUpdateUserId());
			ps.setString(7, dto.getRemark());
			ps.setTimestamp(8, dto.getUpdateTime());
			ps.executeUpdate();			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}		
	}
	/**
	 * 判断判断库存状态是否变化
	 * */
	public boolean  isChangedStockStatus(String serial,int registerStatus)
			throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		boolean flag = false;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" REGISTERSTATUS ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, serial);
			rs = ps.executeQuery();
			while(rs.next()){
				if(rs.getInt("REGISTERSTATUS")==registerStatus)
				{
					flag =false;
				} else {
					flag =true;
				}
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return flag;		
	}
	public void updateRegisterStatus(String serial, int registerStatus)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" REGISTERSTATUS=? ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, registerStatus);
			ps.setString(2,serial);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
	}
	/**
	 * 查找商户ID
	 * */
	public ControlCarDto  findMemberId(String serial)
			throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		ControlCarDto dto = new ControlCarDto();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" MEMBERID, ");
		sql.append(" REGISTERSTATUS ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, serial);
			rs = ps.executeQuery();
			while(rs.next()){
				dto.setmId(rs.getInt("MEMBERID"));
				dto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
			}
			return dto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
				
	}
	/**
	 * 查找
	 * */
	public int getAlreadyTransactionVolumeByMemberId(String memberId)
			throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		int count = 0;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE ");
		sql.append(" MEMBERID=? ");
		sql.append(" AND (REGISTERSTATUS=1 OR REGISTERSTATUS=2 OR REGISTERSTATUS=6) ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, memberId);
			rs = ps.executeQuery();
			while(rs.next()){
				++count;
			}
			return count;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
	
	/**
	 * 查找车牌号码
	 * */
	public List<MarketCarInfoDto> findLicensePlateListByRegisterStatus(String licensePlate)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> dtoList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID, ");
		sql.append(" LICENSEPLATE ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" LICENSEPLATE LIKE '%"+licensePlate+"%' ");
		sql.append(" AND REGISTERSTATUS<>3 AND REGISTERSTATUS <>4 ");
		sql.append(" ORDER BY LICENSEPLATE ASC LIMIT 30");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dtoList.add(dto);
			}
			return dtoList;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		
		} finally {
			super.close(rs, ps);
		}
	}
	
	
	/**
	 * 查找车牌号码
	 * */
	public List<MarketCarInfoDto> findLicensePlateList(String licensePlate)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> dtoList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID, ");
		sql.append(" LICENSEPLATE ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" LICENSEPLATE LIKE '%"+licensePlate+"%' ");
		sql.append(" AND STATUS<>0 AND STATUS <>16 ");
		sql.append(" ORDER BY LICENSEPLATE ASC LIMIT 30");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dtoList.add(dto);
			}
			return dtoList;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		
		} finally {
			super.close(rs, ps);
		}
	}
	
	/**
	 * 查找车架号
	 * */
	public List<MarketCarInfoDto> findVinListByRegisterStatus(String vin)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> dtoList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID, ");
		sql.append(" VIN ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" VIN LIKE '%"+vin+"%' ");
		sql.append(" AND REGISTERSTATUS<>3 AND REGISTERSTATUS <>4 ");
		sql.append(" ORDER BY VIN ASC");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				dto.setVin(rs.getString("VIN"));
				dtoList.add(dto);
			}
			return dtoList;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		
		} finally {
			super.close(rs, ps);
		}
	}
	
	/**
	 * 查找车架号
	 * */
	public List<MarketCarInfoDto> findVinList(String vin,String memberId)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> dtoList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID, ");
		sql.append(" VIN ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" VIN LIKE '%"+vin+"%' ");
		sql.append(" AND MEMBERID ='" +memberId+ "'");
		sql.append(" AND REGISTERSTATUS NOT IN(3,4)");
		sql.append(" ORDER BY VIN ASC");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				dto.setVin(rs.getString("VIN"));
				dtoList.add(dto);
			}
			return dtoList;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		
		} finally {
			super.close(rs, ps);
		}
	}
	
	/**
	 * 查找车架号
	 * */
	public List<MarketCarInfoDto> findVinList(String vin)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> dtoList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID, ");
		sql.append(" VIN ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" VIN LIKE '%"+vin+"%' ");
		sql.append(" ORDER BY VIN ASC");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				dto.setVin(rs.getString("VIN"));
				dtoList.add(dto);
			}
			return dtoList;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		
		} finally {
			super.close(rs, ps);
		}
	}
	/**
	 * 查找车架号
	 * */
	public List<MarketCarInfoDto> findCarInfoListByVin(String vin)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> dtoList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" ID, ");
		sql.append(" VIN, ");
		sql.append(" SERIAL, ");
		sql.append(" REGISTERSTATUS, ");
		sql.append(" tempLicensePlate, ");
		sql.append(" MEMBERID, ");
		sql.append(" UPDATETIME ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" VIN = ?");
		sql.append(" AND REGISTERSTATUS not in (3,4)");
		sql.append(" ORDER BY UPDATETIME DESC");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, vin);
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setMId(rs.getLong("ID"));
				dto.setVin(rs.getString("VIN"));
				dto.setMemberId(rs.getInt("MEMBERID"));
				dto.setSerial(rs.getString("SERIAL"));
				dto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				dto.setTempLicensePlate(rs.getString("tempLicensePlate"));
				dto.setUpdateTime(rs.getTimestamp("UPDATETIME"));
				dtoList.add(dto);
			}
			return dtoList;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		
		} finally {
			super.close(rs, ps);
		}
	}
	public void updateCarMatchInfo(MarketCarInfoDto dto,int tag1Skip,int tag2Skip)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		int i = 0;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" PHOTO_1=").append(tag1Skip == 2 ? "?" : "PHOTO_1").append(",");
		sql.append(" PHOTO_2=").append(tag1Skip == 2 ? "?" : "PHOTO_2").append(",");
		sql.append(" PHOTO_3=").append(tag1Skip == 2 ? "?" : "PHOTO_3").append(",");
		sql.append(" PHOTO_4=").append(tag1Skip == 2 ? "?" : "PHOTO_4").append(",");
		sql.append(" PHOTO_5=").append(tag1Skip == 2 ? "?" : "PHOTO_5").append(",");
		sql.append(" PHOTO_6=").append(tag1Skip == 2 ? "?" : "PHOTO_6").append(",");
		sql.append(" PHOTO_7=").append(tag1Skip == 2 ? "?" : "PHOTO_7").append(",");
		sql.append(" PHOTO_8=").append(tag1Skip == 2 ? "?" : "PHOTO_8").append(",");
		sql.append(" MILEAGE=").append(tag1Skip == 2 ? "?" : "MILEAGE").append(",");
		sql.append(" ATTESTSTATUS=").append(tag2Skip == 2 ? "?" : "ATTESTSTATUS").append(",");		
		sql.append(" UPDATETIME=SYSDATE(),");
		sql.append(" UPDATEUSERID=").append(tag1Skip == 2 ? "?" : "UPDATEUSERID").append(",");
		sql.append(" ENTRYSTATUS=").append(tag1Skip == 2 ? "?" : "ENTRYSTATUS").append(",");
		sql.append(" TEMPLICENSEPLATE=").append(StringUtil.isNotBlank(dto.getTempLicensePlate()) ? "?" : "TEMPLICENSEPLATE").append(",");
		sql.append(" COLOR=").append(tag1Skip == 2 ? "?" : "COLOR");
		sql.append(" WHERE ");
		sql.append(" ID=? ");
		try {
			
			ps = conn.prepareStatement(sql.toString());
			
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_1());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_2());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_3());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_4());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_5());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_6());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_7());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_8());
			if(tag1Skip == 2) ps.setInt(++i, dto.getMileage());
			if(tag2Skip == 2) ps.setInt(++i, dto.getAttestStatus());
			if(tag1Skip == 2) ps.setInt(++i, dto.getUpdateUserId());
			if(tag1Skip == 2) ps.setInt(++i, dto.getEntryStatus());
			if(StringUtil.isNotBlank(dto.getTempLicensePlate())) ps.setString(++i, dto.getTempLicensePlate());
			if(tag1Skip == 2) ps.setInt(++i, dto.getColor());
			ps.setLong(++i, dto.getMId());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}
	public List<MarketCarInfoDto> findCarListInfo(MarketCarInfoDto dto,int type)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> dtoList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" MARKET.ID AS ID, ");		
		sql.append(" MARKET.SERIAL AS SERIAL, ");
		sql.append(" MARKET.LICENSEPLATE AS LICENSEPLATE, ");
		sql.append(" MARKET.VIN AS VIN, ");
		sql.append(" MARKET.PHOTO_1 AS PHOTO_1, ");
		sql.append(" MARKET.INSERTTIME AS INSERTTIME, ");
		sql.append(" SERVICE.ISVALID AS ISVALID, ");
		sql.append(" SERVICE.CHECKIMGPATH AS CHECKIMGPATH, ");
		sql.append(" SERVICE.CHECKUSER AS CHECKUSER, ");
		sql.append(" SERVICE.CHECKTIME AS CHECKTIME, ");
		sql.append(" SERVICE.CHECKPRICE AS CHECKPRICE ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" MARKET");
		sql.append(" LEFT JOIN  ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_SERVICE);
		sql.append(" SERVICE");
		sql.append(" ON SERVICE.SERIAL = MARKET.SERIAL ");
		sql.append(" WHERE " );
		sql.append(" MARKET.REGISTERSTATUS not in (3,4) ");
		if(type == 1){
			sql.append("AND MARKET.SERIAL = '" + dto.getSerial() +"'");
		}else if(type == 2){
			sql.append(" AND MARKET.LICENSEPLATE LIKE '%" + dto.getLicensePlate() + "' ");
		}else if(type == 3){
			sql.append(" AND MARKET.VIN LIKE '%" + dto.getVin() + "' ");
		}
		sql.append(" ORDER BY MARKET.INSERTTIME DESC");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dtoInfo = new MarketCarInfoDto();
				dtoInfo.setMId(rs.getLong("ID"));
				dtoInfo.setSerial(rs.getString("SERIAL"));
				dtoInfo.setLicensePlate(rs.getString("LICENSEPLATE"));
				dtoInfo.setVin(rs.getString("VIN"));
				dtoInfo.setPhoto_1(rs.getString("PHOTO_1"));
				dtoInfo.setInsertTime(rs.getTimestamp("INSERTTIME"));
				dtoInfo.setIsValid(rs.getInt("ISVALID"));
				dtoInfo.setCheckImgPath(rs.getString("CHECKIMGPATH"));
				dtoInfo.setCheckUserName(rs.getString("CHECKUSER"));
				dtoInfo.setCheckTime(rs.getTimestamp("CHECKTIME"));
				dtoInfo.setCheckPrice(rs.getInt("CHECKPRICE"));
				dtoList.add(dtoInfo);
			}
			return dtoList;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		
		} finally {
			super.close(rs, ps);
		}
	}
	public void updateMarketCarIsMatchInfo(MarketCarInfoDto dto,int tag1Skip,int tag2Skip)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		int i = 0;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" PHOTO_1=").append(tag1Skip == 2 ? "?" : "PHOTO_1").append(",");
		sql.append(" PHOTO_2=").append(tag1Skip == 2 ? "?" : "PHOTO_2").append(",");
		sql.append(" PHOTO_3=").append(tag1Skip == 2 ? "?" : "PHOTO_3").append(",");
		sql.append(" PHOTO_4=").append(tag1Skip == 2 ? "?" : "PHOTO_4").append(",");
		sql.append(" PHOTO_5=").append(tag1Skip == 2 ? "?" : "PHOTO_5").append(",");
		sql.append(" PHOTO_6=").append(tag1Skip == 2 ? "?" : "PHOTO_6").append(",");
		sql.append(" PHOTO_7=").append(tag1Skip == 2 ? "?" : "PHOTO_7").append(",");
		sql.append(" PHOTO_8=").append(tag1Skip == 2 ? "?" : "PHOTO_8").append(",");
		sql.append(" MILEAGE=").append(tag1Skip == 2 ? "?" : "MILEAGE").append(",");
		sql.append(" ATTESTSTATUS=").append(tag2Skip == 2 ? "?" : "ATTESTSTATUS").append(",");
		sql.append(" ENTRYSTATUS=").append(tag1Skip == 2 ? "?" : "ENTRYSTATUS").append(",");
		sql.append(" TEMPLICENSEPLATE=").append(StringUtil.isNotBlank(dto.getTempLicensePlate()) ? "?" : "TEMPLICENSEPLATE").append(",");
		sql.append(" COLOR=").append(tag1Skip == 2 ? "?" : "COLOR");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			
			ps = conn.prepareStatement(sql.toString());
			
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_1());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_2());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_3());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_4());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_5());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_6());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_7());
			if(tag1Skip == 2) ps.setString(++i, dto.getPhoto_8());
			if(tag1Skip == 2) ps.setInt(++i, dto.getMileage());
			if(tag2Skip == 2) ps.setInt(++i, dto.getAttestStatus());
			if(tag1Skip == 2) ps.setInt(++i, dto.getEntryStatus());
			if(StringUtil.isNotBlank(dto.getTempLicensePlate())) ps.setString(++i, dto.getTempLicensePlate());
			if(tag1Skip == 2) ps.setInt(++i, dto.getColor());
			ps.setString(++i, dto.getSerial());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}
	
	@Override
	public List<MarketCarInfoDto> findPrivilegeCar() throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> priCarlist = new ArrayList<MarketCarInfoDto>();
		MarketCarInfoDto marketCarInfoDto = null;
		StringBuffer sql = new StringBuffer("");
		
		sql.append("SELECT A.ID,");
		sql.append(" A.TEMPLICENSEPLATE,");
		sql.append(" A.LICENSEPLATE,");
		sql.append(" A.ENTERTIME,");
		sql.append(" CASE A.REGISTERSTATUS WHEN 1 THEN '有效' ELSE '无效' END as REGSTATUS,");
		sql.append(" A.REMARK,");
		sql.append(" A.UPDATETIME,");
		sql.append(" B.REALNAME");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_PRIVILEGE);
		sql.append(" A LEFT JOIN ");
		sql.append(TmsTableNames.TMS_USER);
		sql.append(" B ON A.UPDATEUSERID = B.ID");
		sql.append(" ORDER BY A.REGISTERSTATUS, A.UPDATETIME DESC");
		try {
			ps = conn.prepareStatement(sql.toString());		
			rs = ps.executeQuery();
			int i = 1;
			while (rs.next()) { 
				marketCarInfoDto = new MarketCarInfoDto(); 
				marketCarInfoDto.setPrivilId(rs.getString("ID"));
				marketCarInfoDto.setNum(i);
				if(!(StringUtil.isNULL(rs.getString("LICENSEPLATE"))=="")){
					marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				}else{
					if (!(StringUtil.isNULL(rs.getString("TEMPLICENSEPLATE"))=="") && rs.getString("TEMPLICENSEPLATE").length() == 32){
						marketCarInfoDto.setLicensePlate(rs.getString("TEMPLICENSEPLATE").substring(26, 32));
					}else{	
						marketCarInfoDto.setLicensePlate("");
					}
				}
				marketCarInfoDto.setRegisterStatusPri(rs.getString("REGSTATUS"));
				marketCarInfoDto.setEnterTimeS(rs.getDate("ENTERTIME").toString());
				marketCarInfoDto.setUpdateTime(rs.getDate("UPDATETIME"));
				marketCarInfoDto.setUpdateUserName(rs.getString("REALNAME"));
				marketCarInfoDto.setRemark(rs.getString("REMARK"));
				if(i%2 == 0){
					marketCarInfoDto.setCssFlag(2);
				}else{
					marketCarInfoDto.setCssFlag(1);
				}
				
				priCarlist.add(marketCarInfoDto);
				i ++;
			}
			return priCarlist;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		
	}

	
	public void savePrivilegeCarInfo(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		StringBuffer sql = new StringBuffer("INSERT INTO ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_PRIVILEGE);
		sql.append("(");
		sql.append(" tempLicensePlate, ");
		sql.append(" licensePlate, ");			
		sql.append(" enterTime, ");
		sql.append(" registerStatus, ");
		sql.append(" remark, ");
		sql.append(" updateTime, ");
		sql.append("updateUserId");
		sql.append("  ) VALUES ( ");
		sql.append(" ?,?,?,1,?,SYSDATE(),?)");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, dto.getTempLicensePlate());
			ps.setString(2, dto.getLicensePlate());
			ps.setString(3, dto.getEnterTimeS());
			ps.setString(4, dto.getRemark());
			ps.setInt(5, dto.getUpdateUserId());
			ps.executeUpdate();
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
	
	@Override
	public String findInputInfoTemLP(String tempLicensePlate) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		String tempLP = "";
		StringBuffer sql = new StringBuffer("");
		
		sql.append("SELECT TEMPLICENSEPLATE FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_PRIVILEGE);
		sql.append(" WHERE TEMPLICENSEPLATE = '");
		sql.append(tempLicensePlate);
		sql.append("'");
		
		try {
			ps = conn.prepareStatement(sql.toString());		
			rs = ps.executeQuery();
			while (rs.next()) { 
				tempLP = rs.getString("TEMPLICENSEPLATE");
			}
			return tempLP;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		
	}
	
	public String findInputInfoLP(String licensePlate) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		String lp = "";
		StringBuffer sql = new StringBuffer("");
		
		sql.append("SELECT LICENSEPLATE FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_PRIVILEGE);
		sql.append(" WHERE LICENSEPLATE = '");
		sql.append(licensePlate);
		sql.append("'");
		
		try {
			ps = conn.prepareStatement(sql.toString());		
			rs = ps.executeQuery();
			while (rs.next()) { 
				lp = rs.getString("LICENSEPLATE");
			}
			return lp;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		
	}
	
	@Override
	public MarketCarInfoDto findUpdatePriCarResult(String priviId) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto marketCarInfoDto = new MarketCarInfoDto();
		StringBuffer sql = new StringBuffer("");
		
		sql.append("SELECT ID,");
		sql.append(" TEMPLICENSEPLATE,");
		sql.append(" LICENSEPLATE,");
		sql.append(" ENTERTIME,");
		sql.append(" REGISTERSTATUS,");
		sql.append(" REMARK");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_PRIVILEGE);
		sql.append(" WHERE ID = '");
		sql.append(priviId);
		sql.append("'");
		try {
			ps = conn.prepareStatement(sql.toString());		
			rs = ps.executeQuery();
			while (rs.next()) {
				marketCarInfoDto.setPrivilId(rs.getString("ID"));
			    marketCarInfoDto.setLicensePlate(rs.getString("LICENSEPLATE"));
				marketCarInfoDto.setTempLicensePlate(rs.getString("TEMPLICENSEPLATE"));
				marketCarInfoDto.setRegisterStatusPri(rs.getString("REGISTERSTATUS"));
				marketCarInfoDto.setEnterTimeS(rs.getDate("ENTERTIME").toString());
				marketCarInfoDto.setRemark(rs.getString("REMARK"));
			}
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		
	}
	
	
	public void updatePrivilegeCarInfo(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		StringBuffer sql = new StringBuffer("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_PRIVILEGE);
		sql.append(" SET ");
		sql.append("tempLicensePlate=?, ");
		sql.append("licensePlate=?, ");
		sql.append("enterTime=?, ");
		sql.append("registerStatus=?, ");
		sql.append("remark=?, ");
		sql.append("updateTime=SYSDATE(), ");
		sql.append("updateUserId=? ");
		sql.append("WHERE ");
		sql.append("ID=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, dto.getTempLicensePlate());
			ps.setString(2, dto.getLicensePlate());
			ps.setString(3, dto.getEnterTimeS());
			ps.setString(4, dto.getRegisterStatusPri());
			ps.setString(5, dto.getRemark());
			ps.setInt(6, dto.getUpdateUserId());
			ps.setString(7, dto.getPrivilId());
			ps.executeUpdate();
			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(ps);
		}
	}

	/** 
	 * 自助打印-新车上牌
	 * 
	 * @param vin
	 */
	@Override
	public List<TransferAcceptedInfoDto> loadCarAutoTerminalBrandNewCarList(String vin) throws TmsDaoException {
		List<TransferAcceptedInfoDto> innerCarList = new ArrayList<TransferAcceptedInfoDto>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ");
		sql.append("LC_PRINTNUM,");
		sql.append("CY_PRINTNUM,");
		sql.append("CY_PRINTUSERID, ");
		sql.append("LICENSEPLATE,");
		sql.append("LICENSEPLATECOL, ");
		sql.append("OWNERSGROUPPHOTO, ");
		sql.append("VIN,");
		sql.append("SERIAL,");
		sql.append("CAROWNER,");
		sql.append("TRANSFER,");
		sql.append("CHANGEUSENATURE,");
		sql.append("REPEATVIN,");
		sql.append("REPEATENGINENUM,");
		sql.append("CHANGEALLCAR,");
		sql.append("APPLYCERTIFICATE,");
		sql.append("REPLACEMENTCERTIFICATE,");
		sql.append("MONITORINGSALES,");
		sql.append("OTHER,");
		sql.append("VINNUM,");
		sql.append("ENGINENUM,");
		sql.append("BRANDMODEL,");
		sql.append("CY_COLOR,");
		sql.append("CY_PASSENGER,");
		sql.append("CY_CARTYPE,");
		sql.append("PLATEORTIREEXTERIOR,");
		sql.append("TIREINTACT,");
		sql.append("SEATBELT,");
		sql.append("NUMBERAXES,");
		sql.append("TIRESIZE,");
		sql.append("LATERALPORTIONOF,");
		sql.append("REFLECTIVEMARK,");
		sql.append("FIREEXTINGUISHER,");
		sql.append("DRIVINGRECORD,");
		sql.append("SECURITY,");
		sql.append("EXTERNALMARKING,");
		sql.append("SIREN,");
		sql.append("SECURITYTECHNOLOGY,");
		sql.append("CHECKCONCLUSION,");
		sql.append("PHOTO_1,");
		sql.append("PHOTO_2,");
		sql.append("PHOTO_3,");
		sql.append("PHOTO_4,");
		sql.append("REMARK,");
		sql.append("CY_CARDTYPE,");
		sql.append("BASICCARID, ");
		sql.append("MARKETTYPE, ");
		sql.append("PG_PRINTNUM, ");
		sql.append("DB_PRINTNUM, ");
		sql.append("ZY_PRINTNUM, ");
		sql.append("ZY_PRINTTIME, ");
		sql.append("ZY_PRINTUSERID, ");
		sql.append("GH_PRINTNUM, ");
		sql.append("GH_PRINTTIME, ");
		sql.append("GH_PRINTUSERID, ");
		sql.append("XS_PRINTNUM, ");
		sql.append("XS_PRINTUSERID, ");
		sql.append("XS_PRINTTIME, ");
		sql.append("REGISTRATION, ");
		sql.append("TRANSFERREGISTER, ");
		sql.append("CHANGESVACATE, ");
		sql.append("STATUS, ");
		sql.append("NEWLICENSEPLATE, ");
		sql.append("REAPPLYCERT, ");
		sql.append("ATTACHMEMBERID, ");
		sql.append("PRETRANSFER, ");
		sql.append("TRANSFERPRICE, ");
		sql.append("CARCLASS ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_TRANSFER_ACCEPTED_INFO);
		sql.append(" WHERE ");
		sql.append(" STATUS NOT IN(16,0)");
		sql.append(" AND VIN LIKE '%" + vin + "' ");
		sql.append(" ORDER BY UPDATETIME DESC");
		
		try {
			ps = conn.prepareStatement(getSql(sql.toString()));
			
			rs = ps.executeQuery();
			TransferAcceptedInfoDto dto = null;
			while (rs.next()) {
				dto = new TransferAcceptedInfoDto();
				dto.setSerial(rs.getString("SERIAL"));
				dto.setCy_printUserId(rs.getInt("CY_PRINTUSERID"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setLicensePlateCol(rs.getString("LICENSEPLATECOL"));
				dto.setOwnersGroupPhoto(rs.getString("OWNERSGROUPPHOTO"));
				dto.setLc_printNum(rs.getInt("LC_PRINTNUM"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setVin(rs.getString("VIN"));
				dto.setCarOwner(rs.getString("CAROWNER"));
				dto.setCy_printNum(rs.getInt("CY_PRINTNUM"));
				dto.setTransfer(rs.getInt("TRANSFER"));
				dto.setChangeUsenature(rs.getInt("CHANGEUSENATURE"));
				dto.setRepeatVIN(rs.getInt("REPEATVIN"));
				dto.setRepeatEngineNum(rs.getInt("REPEATENGINENUM"));
				dto.setChangeAllCar(rs.getInt("CHANGEALLCAR"));
				dto.setApplyCertificate(rs.getInt("APPLYCERTIFICATE"));
				dto.setReplacementCertificate(rs.getInt("REPLACEMENTCERTIFICATE"));
				dto.setMonitoringSales(rs.getInt("MONITORINGSALES"));
				dto.setOther(rs.getInt("OTHER"));
				dto.setVinNum(rs.getString("VINNUM"));
				dto.setEngineNum(rs.getString("ENGINENUM"));
				dto.setBrandModel(rs.getString("BRANDMODEL"));
				dto.setCy_color(rs.getString("CY_COLOR"));
				dto.setCy_passenger(rs.getString("CY_PASSENGER"));
				dto.setCarType(rs.getString("CY_CARTYPE"));
				dto.setPlateOrTireExterior(rs.getString("PLATEORTIREEXTERIOR"));
				dto.setTireIntact(rs.getString("TIREINTACT"));
				dto.setSeatBelt(rs.getString("SEATBELT"));
				dto.setNumberAxes(rs.getString("NUMBERAXES"));
				dto.setTireSize(rs.getString("TIRESIZE"));
				dto.setLateralPortionOf(rs.getString("LATERALPORTIONOF"));
				dto.setReflectiveMark(rs.getString("REFLECTIVEMARK"));
				dto.setFireExtinguisher(rs.getString("FIREEXTINGUISHER"));
				dto.setDrivingRecord(rs.getString("DRIVINGRECORD"));
				dto.setSecurity(rs.getString("SECURITY"));
				dto.setExternalMarking(rs.getString("EXTERNALMARKING"));
				dto.setSiren(rs.getString("SIREN"));
				dto.setSecurityTechnology(rs.getString("SECURITYTECHNOLOGY"));
				dto.setCheckConclusion(rs.getString("CHECKCONCLUSION"));
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setPhoto_2(rs.getString("PHOTO_2"));
				dto.setPhoto_3(rs.getString("PHOTO_3"));
				dto.setPhoto_4(rs.getString("PHOTO_4"));
				dto.setRemark(rs.getString("REMARK"));
				dto.setCardType(rs.getInt("CY_CARDTYPE"));
				dto.setBasicCarId(rs.getString("BASICCARID"));
				dto.setMarketType(rs.getInt("MARKETTYPE"));
				dto.setPg_printNum(rs.getInt("PG_PRINTNUM"));
				dto.setDb_printNum(rs.getInt("DB_PRINTNUM"));
				dto.setZy_printnum(rs.getInt("ZY_PRINTNUM")); 
				dto.setZy_printTime(rs.getTimestamp("ZY_PRINTTIME"));
				dto.setZy_printUserId(rs.getInt("ZY_PRINTUSERID"));
				dto.setGh_printnum(rs.getInt("GH_PRINTNUM")); 
				dto.setGh_printTime(rs.getTimestamp("GH_PRINTTIME"));
				dto.setGh_printUserId(rs.getInt("GH_PRINTUSERID"));		
				dto.setXs_printnum(rs.getInt("XS_PRINTNUM"));
				dto.setXs_printUserId(rs.getInt("XS_PRINTUSERID"));
				dto.setXs_printTime(rs.getTimestamp("XS_PRINTTIME"));
				dto.setRegistration(rs.getInt("REGISTRATION"));
				dto.setTransferRegister(rs.getInt("TRANSFERREGISTER"));
				dto.setChangesVacate(rs.getInt("CHANGESVACATE"));
				dto.setStatus(rs.getInt("STATUS")); 
				dto.setNewLicensePlate(rs.getString("NEWLICENSEPLATE")); 
				dto.setReapplyCert(rs.getInt("REAPPLYCERT")); 
				dto.setAttachMemberId(rs.getString("ATTACHMEMBERID")); 
				dto.setCarClass(rs.getInt("CARCLASS"));
				dto.setPreTransfer(rs.getInt("PRETRANSFER"));
				dto.setTransferPrice(rs.getInt("TRANSFERPRICE"));
				// 特殊处理，临时借用
				dto.setVinNum(rs.getString("VIN"));
				// 短位vin码6位
				String strVin = rs.getString("VIN"); 
//				if (strVin != null && strVin.length() > 6) {
//					strVin = strVin.substring(strVin.length() - 6);
//				} 
				dto.setVin(strVin);
				innerCarList.add(dto);
			}
			return innerCarList;
			
		} 
		
		catch (SQLException e) {
			throw new TmsDaoException(e.toString());
			
		} finally {
			super.close(rs, ps);
		}
	}
	
	/**
	 * 打印查验表
	 */
	@Override
	public void updateTransferCyPrintNumByVin(TransferAcceptedInfoDto dto)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;

		try {
			StringBuffer sql = new StringBuffer("UPDATE ");
			sql.append(TmsTableNames.TMS_TRANSFER_ACCEPTED_INFO);
			sql.append(" SET  ");
			sql.append(" CY_PRINTNUM=?,");
			sql.append(" PG_PRINTTIME=SYSDATE(),");
			sql.append(" CY_PRINTTIME=SYSDATE(),");
			sql.append(" CY_PRINTUSERID=1 ");
			sql.append(" WHERE ");
			sql.append(" STATUS NOT IN(16)");
			sql.append(" AND VIN =? ");
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, dto.getCy_printNum()+1);
			ps.setString(2, dto.getVinNum());  // 临时借用该字段
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
	
	
	/** 
	 * 自助打印-二手车上牌
	 * 
	 * @param vin
	 */
	@Override
	public List<TransferAcceptedInfoDto> loadCarAutoTerminalSecondHandList(TransferAcceptedInfoDto dto) throws TmsDaoException {
		List<TransferAcceptedInfoDto> innerCarList = new ArrayList<TransferAcceptedInfoDto>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ");
		sql.append("LC_PRINTNUM,");
		sql.append("CY_PRINTNUM,");
		sql.append("CY_PRINTUSERID, ");
		sql.append("LICENSEPLATE,");
		sql.append("LICENSEPLATECOL, ");
		sql.append("OWNERSGROUPPHOTO, ");
		sql.append("VIN,");
		sql.append("SERIAL,");
		sql.append("CAROWNER,");
		sql.append("TRANSFER,");
		sql.append("CHANGEUSENATURE,");
		sql.append("REPEATVIN,");
		sql.append("REPEATENGINENUM,");
		sql.append("CHANGEALLCAR,");
		sql.append("APPLYCERTIFICATE,");
		sql.append("REPLACEMENTCERTIFICATE,");
		sql.append("MONITORINGSALES,");
		sql.append("OTHER,");
		sql.append("VINNUM,");
		sql.append("ENGINENUM,");
		sql.append("BRANDMODEL,");
		sql.append("CY_COLOR,");
		sql.append("CY_PASSENGER,");
		sql.append("CY_CARTYPE,");
		sql.append("PLATEORTIREEXTERIOR,");
		sql.append("TIREINTACT,");
		sql.append("SEATBELT,");
		sql.append("NUMBERAXES,");
		sql.append("TIRESIZE,");
		sql.append("LATERALPORTIONOF,");
		sql.append("REFLECTIVEMARK,");
		sql.append("FIREEXTINGUISHER,");
		sql.append("DRIVINGRECORD,");
		sql.append("SECURITY,");
		sql.append("EXTERNALMARKING,");
		sql.append("SIREN,");
		sql.append("SECURITYTECHNOLOGY,");
		sql.append("CHECKCONCLUSION,");
		sql.append("PHOTO_1,");
		sql.append("PHOTO_2,");
		sql.append("PHOTO_3,");
		sql.append("PHOTO_4,");
		sql.append("REMARK,");
		sql.append("CY_CARDTYPE,");
		sql.append("BASICCARID, ");
		sql.append("MARKETTYPE, ");
		sql.append("PG_PRINTNUM, ");
		sql.append("DB_PRINTNUM, ");
		sql.append("ZY_PRINTNUM, ");
		sql.append("ZY_PRINTTIME, ");
		sql.append("ZY_PRINTUSERID, ");
		sql.append("GH_PRINTNUM, ");
		sql.append("GH_PRINTTIME, ");
		sql.append("GH_PRINTUSERID, ");
		sql.append("XS_PRINTNUM, ");
		sql.append("XS_PRINTUSERID, ");
		sql.append("XS_PRINTTIME, ");
		sql.append("REGISTRATION, ");
		sql.append("TRANSFERREGISTER, ");
		sql.append("CHANGESVACATE, ");
		sql.append("STATUS, ");
		sql.append("NEWLICENSEPLATE, ");
		sql.append("REAPPLYCERT, ");
		sql.append("ATTACHMEMBERID, ");
		sql.append("CARCLASS, ");
		sql.append("transferPrice ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_TRANSFER_ACCEPTED_INFO);
		sql.append(" WHERE ");
		sql.append(" CARCLASS = 2 ");
		sql.append(" AND STATUS NOT IN(0,16)");
		sql.append(" AND LICENSEPLATE = '" + dto.getLicensePlate() + "'");
		sql.append(" AND CY_CARDTYPE = '" + dto.getLicensePlateCol() + "'");
		sql.append(" ORDER BY UPDATETIME DESC");
		
		try {
			ps = conn.prepareStatement(getSql(sql.toString()));
			
			rs = ps.executeQuery();
			while (rs.next()) {
				dto = new TransferAcceptedInfoDto();
				dto.setSerial(rs.getString("SERIAL"));
				dto.setCy_printUserId(rs.getInt("CY_PRINTUSERID"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setLicensePlateCol(rs.getString("CY_CARDTYPE"));
				dto.setOwnersGroupPhoto(rs.getString("OWNERSGROUPPHOTO"));
				dto.setLc_printNum(rs.getInt("LC_PRINTNUM"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));
				dto.setVin(rs.getString("VIN"));
				dto.setCarOwner(rs.getString("CAROWNER"));
				dto.setCy_printNum(rs.getInt("CY_PRINTNUM"));
				dto.setTransfer(rs.getInt("TRANSFER"));
				dto.setChangeUsenature(rs.getInt("CHANGEUSENATURE"));
				dto.setRepeatVIN(rs.getInt("REPEATVIN"));
				dto.setRepeatEngineNum(rs.getInt("REPEATENGINENUM"));
				dto.setChangeAllCar(rs.getInt("CHANGEALLCAR"));
				dto.setApplyCertificate(rs.getInt("APPLYCERTIFICATE"));
				dto.setReplacementCertificate(rs.getInt("REPLACEMENTCERTIFICATE"));
				dto.setMonitoringSales(rs.getInt("MONITORINGSALES"));
				dto.setOther(rs.getInt("OTHER"));
				dto.setVinNum(rs.getString("VINNUM"));
				dto.setEngineNum(rs.getString("ENGINENUM"));
				dto.setBrandModel(rs.getString("BRANDMODEL"));
				dto.setCy_color(rs.getString("CY_COLOR"));
				dto.setCy_passenger(rs.getString("CY_PASSENGER"));
				dto.setCarType(rs.getString("CY_CARTYPE"));
				dto.setPlateOrTireExterior(rs.getString("PLATEORTIREEXTERIOR"));
				dto.setTireIntact(rs.getString("TIREINTACT"));
				dto.setSeatBelt(rs.getString("SEATBELT"));
				dto.setNumberAxes(rs.getString("NUMBERAXES"));
				dto.setTireSize(rs.getString("TIRESIZE"));
				dto.setLateralPortionOf(rs.getString("LATERALPORTIONOF"));
				dto.setReflectiveMark(rs.getString("REFLECTIVEMARK"));
				dto.setFireExtinguisher(rs.getString("FIREEXTINGUISHER"));
				dto.setDrivingRecord(rs.getString("DRIVINGRECORD"));
				dto.setSecurity(rs.getString("SECURITY"));
				dto.setExternalMarking(rs.getString("EXTERNALMARKING"));
				dto.setSiren(rs.getString("SIREN"));
				dto.setSecurityTechnology(rs.getString("SECURITYTECHNOLOGY"));
				dto.setCheckConclusion(rs.getString("CHECKCONCLUSION"));
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setPhoto_2(rs.getString("PHOTO_2"));
				dto.setPhoto_3(rs.getString("PHOTO_3"));
				dto.setPhoto_4(rs.getString("PHOTO_4"));
				dto.setRemark(rs.getString("REMARK"));
				dto.setCardType(rs.getInt("CY_CARDTYPE"));
				dto.setBasicCarId(rs.getString("BASICCARID"));
				dto.setMarketType(rs.getInt("MARKETTYPE"));
				dto.setPg_printNum(rs.getInt("PG_PRINTNUM"));
				dto.setDb_printNum(rs.getInt("DB_PRINTNUM"));
				dto.setZy_printnum(rs.getInt("ZY_PRINTNUM")); 
				dto.setZy_printTime(rs.getTimestamp("ZY_PRINTTIME"));
				dto.setZy_printUserId(rs.getInt("ZY_PRINTUSERID"));
				dto.setGh_printnum(rs.getInt("GH_PRINTNUM")); 
				dto.setGh_printTime(rs.getTimestamp("GH_PRINTTIME"));
				dto.setGh_printUserId(rs.getInt("GH_PRINTUSERID"));		
				dto.setXs_printnum(rs.getInt("XS_PRINTNUM"));
				dto.setXs_printUserId(rs.getInt("XS_PRINTUSERID"));
				dto.setXs_printTime(rs.getTimestamp("XS_PRINTTIME"));
				dto.setRegistration(rs.getInt("REGISTRATION"));
				dto.setTransferRegister(rs.getInt("TRANSFERREGISTER"));
				dto.setChangesVacate(rs.getInt("CHANGESVACATE"));
				dto.setStatus(rs.getInt("STATUS")); 
				dto.setNewLicensePlate(rs.getString("NEWLICENSEPLATE")); 
				dto.setReapplyCert(rs.getInt("REAPPLYCERT")); 
				dto.setAttachMemberId(rs.getString("ATTACHMEMBERID")); 
				dto.setCarClass(rs.getInt("CARCLASS"));
				dto.setTransferPrice(rs.getInt("transferPrice"));
				innerCarList.add(dto);
			}
			return innerCarList;
			
		} 
		
		catch (SQLException e) {
			throw new TmsDaoException(e.toString());
			
		} finally {
			super.close(rs, ps);
		}
	}
	
	/**
	 * 打印查验表
	 */
	@Override
	public void updateTransferCyPrintNumByLicensePlate(TransferAcceptedInfoDto dto)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;

		try {
			StringBuffer sql = new StringBuffer("UPDATE ");
			sql.append(TmsTableNames.TMS_TRANSFER_ACCEPTED_INFO);
			sql.append(" SET  ");
			sql.append(" CY_PRINTNUM=?,");
			sql.append(" PG_PRINTTIME=SYSDATE(),");
			sql.append(" CY_PRINTTIME=SYSDATE(),");
			sql.append(" CY_PRINTUSERID=1 ");
			sql.append(" WHERE ");
			sql.append(" CARCLASS = 2 ");
			sql.append(" AND STATUS NOT IN(0,16)");
			sql.append(" AND LICENSEPLATE=? ");
			sql.append(" AND LICENSEPLATECOL=? ");
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, dto.getCy_printNum()+1);
			ps.setString(2, dto.getLicensePlate());
			ps.setString(3, dto.getLicensePlateCol()); 
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}
	
	/**
	 * 关联的库存车辆业务信息表（tms_market_car_service） 流程表缴费（checkPrice）+交易票缴费（transferPrice）
	 * 
	 * @param serial
	 * @return
	 * @throws TmsDaoException
	 */
	public MarketCarServiceDto findMarketCarService(String serial)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> dtoList = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" SERVICE.ID AS ID, ");		
		sql.append(" SERVICE.SERIAL AS SERIAL, ");
		sql.append(" SERVICE.CHECKPRICE AS CHECKPRICE, ");
		sql.append(" SERVICE.TRANSFERPRICE AS TRANSFERPRICE ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_SERVICE);
		sql.append(" SERVICE");
		sql.append(" WHERE " );
		sql.append(" SERVICE.SERIAL = '" + serial +"'");
		
		MarketCarServiceDto dtoInfo = new MarketCarServiceDto();
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				dtoInfo.setId(rs.getInt("ID"));
				dtoInfo.setSerial(rs.getString("SERIAL"));
				dtoInfo.setCheckPrice(rs.getInt("CHECKPRICE"));
				dtoInfo.setTransferPrice(rs.getInt("TRANSFERPRICE"));
			}
			return dtoInfo;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		
		} finally {
			super.close(rs, ps);
		}
	}
	public void updateMember(int memberId, int price)
			throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MEMBER);
		sql.append(" SET ");
		sql.append(" VIRTUALMARGIN=(VIRTUALMARGIN + ?) ");
		sql.append(" WHERE ");
		sql.append(" MEMBERID=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, price);
			ps.setInt(2,memberId);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
	}
	
	/**
	 * 更新 库存车辆业务表（tms_market_car_service）
	 * 
	 * @param serial
	 * @throws TmsDaoException
	 */
	@Override
	public void updateMarketCarService(String serial) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_SERVICE);
		sql.append(" SET  ");
		sql.append(" CHECKSTATUS = 1 , ");
		sql.append(" CHECKIMGPATH = null , ");
		sql.append(" CHECKUSER = null , ");
		sql.append(" CHECKTIME = null , ");
		sql.append(" CHECKVALIDTIME = null , ");
		sql.append(" ISVALID = 3 , ");
		sql.append(" CHECKPRICE = 0 , ");
		sql.append(" ISREBATE = 0 , ");
		sql.append(" TRANSFERPRICE = 0  ");
		sql.append(" WHERE  ");
		sql.append(" SERIAL=");
		sql.append("'");
		sql.append(serial);
		sql.append("'");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
	}
	public void updateCarLicensePlateInfo(MarketCarInfoDto marketCarInfoDto) throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" LICENSEPLATE=?, ");
		sql.append(" NEWLICENSEPLATE=?, ");
		sql.append(" UPDATEUSERID=?, ");
		sql.append(" UPDATETIME=SYSDATE(), ");		
		sql.append(" CHGLICENSEPLATETIME=SYSDATE() ");
		sql.append(" WHERE  ");
		sql.append(" SERIAL=? ");
		try {
			
			ps = conn.prepareStatement(sql.toString());
			
			ps.setString(1, marketCarInfoDto.getLicensePlate());
			ps.setString(2, marketCarInfoDto.getNewLicensePlate());
			ps.setInt(3, marketCarInfoDto.getUpdateUserId());
			ps.setString(4, marketCarInfoDto.getSerial());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}
	/**
	 * 通过车架号查找车辆信息 
	 * */
	public MarketCarInfoDto findMarketCarInfoListByVin(String vin)throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		MarketCarInfoDto dto = new MarketCarInfoDto();
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" SERIAL, ");
		sql.append(" LICENSEPLATE, ");
		sql.append(" MEMBERID ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE " );
		sql.append(" VIN = ?");
		sql.append(" AND REGISTERSTATUS not in (3,4)");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, vin);
			rs = ps.executeQuery();
			while(rs.next()){
				dto.setSerial(rs.getString("SERIAL"));
				dto.setLicensePlate(rs.getString("LICENSEPLATE"));			
				dto.setMemberId(rs.getInt("MEMBERID"));
			}			
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		
		} finally {
			super.close(rs, ps);
		}
		return dto;
	}
	
	/**
	 * 更新 库存车辆业务表（tms_market_car_service）
	 * 
	 * @param serial
	 * @throws TmsDaoException
	 */
	@Override
	public void updateMarketCarServiceByMq203(String serial,int checkPrice, int  transferPrice) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_SERVICE);
		sql.append(" SET  ");
		sql.append(" CHECKSTATUS = 1 , ");
		sql.append(" CHECKIMGPATH = null , ");
		sql.append(" CHECKUSER = null , ");
		sql.append(" CHECKTIME = null , ");
		sql.append(" CHECKVALIDTIME = null , ");
		sql.append(" ISVALID = 3 , ");
		sql.append(" CHECKPRICE = '"+checkPrice+"' , ");
		sql.append(" TRANSFERPRICE = '"+transferPrice+"'  ");
		sql.append(" WHERE  ");
		sql.append(" SERIAL=");
		sql.append("'");
		sql.append(serial);
		sql.append("'");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}	
	}
	/**
	 * 查找商户短名
	 * 
	 * @param serial
	 * @throws TmsDaoException
	 */
	@Override
	public String findShortNameBySerial(String serial) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;		
		String shortName = "";
		
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ");
		sql.append(" MEMBER.SHORTNAME AS SHORTNAME");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" MARKET");
		sql.append(" LEFT JOIN  ");
		sql.append(TmsTableNames.TMS_MEMBER);
		sql.append(" MEMBER ");
		sql.append(" ON MEMBER.MEMBERID=MARKET.MEMBERID");
		sql.append(" WHERE");
		sql.append(" MARKET.SERIAL = ? ");
		
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, serial);
			rs = ps.executeQuery();
			while (rs.next()) {
				shortName = rs.getString("SHORTNAME");
			}
			return shortName;			
		}		
		catch (SQLException e) {
			throw new TmsDaoException(e.toString());
			
		} finally {
			super.close(rs, ps);
		}		
	}
	public void updateTmpStorageEnterTime(MarketCarInfoDto marketCarInfoDto) throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" TMPSTORAGETIME=?, ");
		sql.append(" TMPENTERTIME=? ");
		sql.append(" WHERE  ");
		sql.append(" SERIAL=? ");
		try {
			
			ps = conn.prepareStatement(sql.toString());
			
			ps.setTimestamp(1, marketCarInfoDto.getTmpStorageTime());
			ps.setTimestamp(2, marketCarInfoDto.getTmpEnterTime());
			ps.setString(3, marketCarInfoDto.getSerial());
			
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}


	@Override
	public int getCarByMemberIdCount(String memberId) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT COUNT(ID) as COUNT ");
		sql.append(" FROM "+TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" WHERE 	MEMBERID = ? ");
		sql.append(" AND REGISTERSTATUS = 1 AND ENTRYSTATUS <> 2 AND ISSHELVE = 1 ORDER BY 	INSERTTIME DESC ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, memberId);
			rs = ps.executeQuery();
			while(rs.next()) return rs.getInt("COUNT");
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
		return 0;
	}


	@Override
	public List findPageCarByMemberId(String memberId, int pageNumber, int pageSize) throws TmsDaoException {
		int limitStart = pageNumber * pageSize - pageSize;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" 	A.ID, ");
		sql.append(" 	A.REGISTERSTATUS, ");
		sql.append(" 	A.ENTRYSTATUS, ");
		sql.append(" 	A.ISSHELVE, ");
		sql.append(" 	A.PHOTO_1, ");
		sql.append(" 	A.ATTESTSTATUS, ");
		sql.append(" 	round(A.PRICE/10000,2) as PRICE, ");
		sql.append(" 	round(A.MILEAGE/ 10000,2) AS MILEAGE, ");
		sql.append(" 	DATE_FORMAT(A.REGDATE,'%Y-%m') as REGDATE, ");
		sql.append(" 	A.CARSTYLEID, ");
		sql.append(" 	B.STYLENAME, ");
		sql.append(" 	B.EMISSIONSTANGARD, ");
		sql.append("    C.RECOMMEND, ");
		sql.append("    C.SHORTNAME, ");
		sql.append("    A.ATTESTSTATUS, ");//
		sql.append("    A.COLOR, ");
		sql.append("    A.REMARK, ");
		sql.append("    A.PHOTO_2, ");
		sql.append("    A.PHOTO_3, ");
		sql.append("    A.PHOTO_4, ");
		sql.append("    A.PHOTO_5, ");
		sql.append("    A.PHOTO_6, ");
		sql.append("    A.PHOTO_7, ");
		sql.append("    A.PHOTO_8, ");
		sql.append("    B.EXHAUST, ");
		sql.append("    B.GEARBOX, ");
		sql.append("    C.MEMBERLOCOLLOGO ");
		sql.append(" FROM ");
		sql.append(" 	"+TmsTableNames.TMS_MARKET_CAR_INFO+" A ");
		sql.append(" LEFT JOIN "+TmsTableNames.TMS_CAR_STYLE+" B ON (A.CARSTYLEID = B.ID) ");
		sql.append(" LEFT JOIN "+TmsTableNames.TMS_MEMBER+" C ON (A.MEMBERID = C.MEMBERID) ");
		sql.append(" WHERE ");
		sql.append(" 	A.MEMBERID = ? ");
		sql.append(" AND A.REGISTERSTATUS = 1 ");
		sql.append(" AND A.ENTRYSTATUS <> 2 ");
		sql.append(" AND A.ISSHELVE = 1 ");
		sql.append(" ORDER BY A.INSERTTIME DESC ");
		sql.append(" LIMIT ").append(limitStart).append(",").append(pageSize);
		List<MarketCarInfoDto> list = new ArrayList<MarketCarInfoDto>();
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, memberId);
			rs = ps.executeQuery();
			int i=0;
			Codes code = Codes.getInstance();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setNum(++i);
				dto.setId(rs.getInt("ID"));
				if(i%2 == 0) dto.setCssFlag(2); 
				else dto.setCssFlag(1);	
				dto.setRegisterStatus(rs.getInt("REGISTERSTATUS"));
				dto.setEntryStatus(rs.getInt("ENTRYSTATUS"));
				dto.setIsShelve(rs.getInt("ISSHELVE"));
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				dto.setThousandPrice(rs.getString("PRICE"));
				dto.setMileage(rs.getInt("MILEAGE"));
				dto.setRegDate(rs.getString("REGDATE"));
				dto.setCarStyleId(rs.getString("CARSTYLEID"));
				dto.setStyleName(rs.getString("STYLENAME"));
				dto.setEmissionStangard(rs.getString("EMISSIONSTANGARD"));
				dto.setRecommend(rs.getString("RECOMMEND"));
				dto.setShortName(rs.getString("SHORTNAME"));
				dto.setAttestStatus(rs.getInt("ATTESTSTATUS"));//
				dto.setColor(rs.getInt("COLOR"));
				dto.setColorName(code.getItemValueByItemIdAndItemCode(Codes.VEHICLE_COLOR,rs.getInt("COLOR")));
				dto.setRemark(rs.getString("REMARK"));
				dto.setPhoto_2(rs.getString("PHOTO_2"));
				dto.setPhoto_3(rs.getString("PHOTO_3"));
				dto.setPhoto_4(rs.getString("PHOTO_4"));
				dto.setPhoto_5(rs.getString("PHOTO_5"));
				dto.setPhoto_6(rs.getString("PHOTO_6"));
				dto.setPhoto_7(rs.getString("PHOTO_7"));
				dto.setPhoto_8(rs.getString("PHOTO_8"));
				dto.setExhaust(StringUtil.getNewExhaust(rs.getInt("EXHAUST")));
				dto.setGearboxName(code.getItemValueByItemIdAndItemCode(Codes.GEARBOX_TYPE, rs.getInt("GEARBOX")));
				dto.setMemberLocolLogo(rs.getString("MEMBERLOCOLLOGO"));
				list.add(dto);
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
		return list;
	}


	@Override
	public int getMarketCarInfoCountByCarStyleId(String carStyleId) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" 	COUNT(A.ID) AS COUNT ");
		sql.append(" FROM ");
		sql.append(" 	"+TmsTableNames.TMS_MARKET_CAR_INFO+" A  ");
		sql.append(" WHERE carStyleId = ?;  ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, carStyleId);
			rs = ps.executeQuery();
			while(rs.next()) return rs.getInt("COUNT");
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
		return 0;
	}


	@Override
	public List getMarketCarInfoByCarStyleId(String carStyleId, int pageNumber, int pageSize) throws TmsDaoException {
		int limitStart = pageNumber * pageSize - pageSize;
		PreparedStatement ps = null; ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" 	A.ID, ");
		sql.append(" 	A.PHOTO_1, ");
		sql.append(" 	A.attestStatus, ");
		sql.append(" 	round(A.PRICE / 10000,2) AS PRICE, ");
		sql.append(" 	round(A.MILEAGE/ 10000,2) AS MILEAGE, ");
		sql.append(" 	DATE_FORMAT(A.REGDATE,'%Y-%m') AS REGDATE, ");
		sql.append(" 	B.EMISSIONSTANGARD, ");
		sql.append("   C.RECOMMEND, ");
		sql.append("   B.STYLENAME, ");
		sql.append(" 	A.ATTESTSTATUS, ");
		sql.append(" 	A.CARSTYLEID, ");
		sql.append("    A.COLOR, ");
		sql.append("    A.REMARK, ");
		sql.append("    A.PHOTO_2, ");
		sql.append("    A.PHOTO_3, ");
		sql.append("    A.PHOTO_4, ");
		sql.append("    A.PHOTO_5, ");
		sql.append("    A.PHOTO_6, ");
		sql.append("    A.PHOTO_7, ");
		sql.append("    A.PHOTO_8, ");
		sql.append("    B.EXHAUST, ");
		sql.append("    B.GEARBOX, ");
		sql.append("    C.MEMBERLOCOLLOGO, ");
		sql.append("   C.SHORTNAME ");
		sql.append(" FROM ");
		sql.append(" 	"+TmsTableNames.TMS_MARKET_CAR_INFO+" A ");
		sql.append(" LEFT JOIN "+TmsTableNames.TMS_CAR_STYLE+" B ON (A.CARSTYLEID = B.ID) ");
		sql.append(" LEFT JOIN "+TmsTableNames.TMS_MEMBER+" C ON (A.MEMBERID = C.MEMBERID) ");
		sql.append(" WHERE A.carStyleId = ? ");
		sql.append(" AND A.REGISTERSTATUS =1 ");
		sql.append(" AND A.ENTRYSTATUS <> 2 ");
		sql.append(" AND A.ISSHELVE = 1 ");
		sql.append(" LIMIT ").append(limitStart).append(",").append(pageSize);
		List<MarketCarInfoDto> list = new ArrayList<MarketCarInfoDto>();
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, carStyleId);
			rs = ps.executeQuery();
			int i=0;
			Codes code = Codes.getInstance();
			while(rs.next()){
				i++;
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				if(i%2 == 0) dto.setCssFlag(2); 
				else dto.setCssFlag(1);	
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setThousandPrice(rs.getString("PRICE"));
				dto.setMileage(rs.getInt("MILEAGE"));
				dto.setRegDate(rs.getString("REGDATE"));
				dto.setStyleName(rs.getString("STYLENAME"));
				dto.setAttestStatus(rs.getInt("attestStatus"));
				dto.setEmissionStangard(rs.getString("EMISSIONSTANGARD"));
				dto.setRecommend(rs.getString("RECOMMEND"));
				dto.setShortName(rs.getString("SHORTNAME"));
				dto.setAttestStatus(rs.getInt("ATTESTSTATUS"));//
				dto.setColor(rs.getInt("COLOR"));
				dto.setColorName(code.getItemValueByItemIdAndItemCode(Codes.VEHICLE_COLOR,rs.getInt("COLOR")));
				dto.setRemark(rs.getString("REMARK"));
				dto.setPhoto_2(rs.getString("PHOTO_2"));
				dto.setPhoto_3(rs.getString("PHOTO_3"));
				dto.setPhoto_4(rs.getString("PHOTO_4"));
				dto.setPhoto_5(rs.getString("PHOTO_5"));
				dto.setPhoto_6(rs.getString("PHOTO_6"));
				dto.setPhoto_7(rs.getString("PHOTO_7"));
				dto.setPhoto_8(rs.getString("PHOTO_8"));
				dto.setCarStyleId(rs.getString("CARSTYLEID"));
				dto.setExhaust(rs.getString("EXHAUST"));
				dto.setGearboxName(code.getItemValueByItemIdAndItemCode(Codes.GEARBOX_TYPE, rs.getInt("GEARBOX")));
				dto.setMemberLocolLogo(rs.getString("MEMBERLOCOLLOGO"));
				list.add(dto);
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
		return list;
	}
	
	public int getMarketCarPriceCount(double minPrice,double maxPrice) throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" 	COUNT(A.ID) AS COUNT ");
		sql.append(" FROM ");
		sql.append(" 	"+TmsTableNames.TMS_MARKET_CAR_INFO+" A  ");
		sql.append(" WHERE PRICE >= ? and PRICE <= ?");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setDouble(1, minPrice);
			ps.setDouble(2, maxPrice);
			rs = ps.executeQuery();
			while(rs.next()) return rs.getInt("COUNT");
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
		return 0;
	}

	@Override
	public void updateMarketCarInfoFor204(MarketCarInfoDto marketCarInfoDto) throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" LICENSEPLATE=? ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, marketCarInfoDto.getLicensePlate());
			ps.setString(2,marketCarInfoDto.getSerial());

			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}
	@Override
	public void updateMarketCarInfoFor205(MarketCarInfoDto marketCarInfoDto) throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" VIN=? ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1,marketCarInfoDto.getVin());
			ps.setString(2,marketCarInfoDto.getSerial());

			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}

	@Override
	public void updateMarketCarInfoFor206(MarketCarInfoDto marketCarInfoDto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" REGISTERSTATUS=? ");
		sql.append(" WHERE ");
		sql.append(" SERIAL=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1,marketCarInfoDto.getRegisterStatus());
			ps.setString(2,marketCarInfoDto.getSerial());

			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}

	public List getMarketCarPrice(double minPrice,double maxPrice, int pageNumber, int pageSize) throws TmsDaoException {
		int limitStart = pageNumber * pageSize - pageSize;
		PreparedStatement ps = null; ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT ");
		sql.append(" 	A.ID, ");
		sql.append(" 	A.PHOTO_1, ");
		sql.append(" 	A.ATTESTSTATUS, ");
		sql.append(" 	ROUND(A.PRICE / 10000,2) AS PRICE, ");
		sql.append(" 	ROUND(A.MILEAGE/ 10000,2) AS MILEAGE, ");
		sql.append(" 	DATE_FORMAT(A.REGDATE,'%Y-%m') AS REGDATE, ");
		sql.append(" 	B.EMISSIONSTANGARD, ");
		sql.append("    B.STYLENAME, ");
		sql.append("    C.RECOMMEND, ");
		sql.append("    C.SHORTNAME, ");
		sql.append("    A.ATTESTSTATUS, ");//
		sql.append("    A.COLOR, ");
		sql.append("    A.REMARK, ");
		sql.append("    A.PHOTO_2, ");
		sql.append("    A.PHOTO_3, ");
		sql.append("    A.PHOTO_4, ");
		sql.append("    A.PHOTO_5, ");
		sql.append("    A.PHOTO_6, ");
		sql.append("    A.PHOTO_7, ");
		sql.append("    A.PHOTO_8, ");
		sql.append("    B.EXHAUST, ");
		sql.append("    B.GEARBOX, ");
		sql.append("    C.MEMBERLOCOLLOGO ");
		sql.append(" FROM ");
		sql.append(" 	"+TmsTableNames.TMS_MARKET_CAR_INFO+" A ");
		sql.append(" LEFT JOIN "+TmsTableNames.TMS_CAR_STYLE+" B ON (A.CARSTYLEID = B.ID) ");
		sql.append(" LEFT JOIN "+TmsTableNames.TMS_MEMBER+" C ON (A.MEMBERID = C.MEMBERID) ");
		sql.append(" WHERE A.PRICE >= ? AND A.PRICE <= ?");
		sql.append(" AND A.REGISTERSTATUS=1 AND A.ENTRYSTATUS!=2 AND A.ISSHELVE=1");
		sql.append(" LIMIT ").append(limitStart).append(",").append(pageSize);
		List<MarketCarInfoDto> list = new ArrayList<MarketCarInfoDto>();
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setDouble(1, minPrice);
			ps.setDouble(2, maxPrice);
			rs = ps.executeQuery();
			int i=0;
			Codes code = Codes.getInstance();
			while(rs.next()){
				i++;
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				if(i%2 == 0) dto.setCssFlag(2); 
				else dto.setCssFlag(1);	
				dto.setPhoto_1(rs.getString("PHOTO_1"));
				dto.setThousandPrice(rs.getString("PRICE"));
				dto.setMileage(rs.getInt("MILEAGE"));
				dto.setRegDate(rs.getString("REGDATE"));
				dto.setAttestStatus(rs.getInt("attestStatus"));
				dto.setStyleName(rs.getString("STYLENAME"));
				dto.setEmissionStangard(rs.getString("EMISSIONSTANGARD"));
				dto.setRecommend(rs.getString("RECOMMEND"));
				dto.setShortName(rs.getString("SHORTNAME"));
				dto.setAttestStatus(rs.getInt("ATTESTSTATUS"));
				dto.setColor(rs.getInt("COLOR"));
				dto.setColorName(code.getItemValueByItemIdAndItemCode(Codes.VEHICLE_COLOR,rs.getInt("COLOR")));
				dto.setRemark(rs.getString("REMARK"));
				dto.setPhoto_2(rs.getString("PHOTO_2"));
				dto.setPhoto_3(rs.getString("PHOTO_3"));
				dto.setPhoto_4(rs.getString("PHOTO_4"));
				dto.setPhoto_5(rs.getString("PHOTO_5"));
				dto.setPhoto_6(rs.getString("PHOTO_6"));
				dto.setPhoto_7(rs.getString("PHOTO_7"));
				dto.setPhoto_8(rs.getString("PHOTO_8"));
				dto.setExhaust(StringUtil.getNewExhaust(rs.getInt("EXHAUST")));
				dto.setGearboxName(code.getItemValueByItemIdAndItemCode(Codes.GEARBOX_TYPE, rs.getInt("GEARBOX")));
				dto.setMemberLocolLogo(rs.getString("MEMBERLOCOLLOGO"));
				list.add(dto);
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
		return list;
	}


	@Override
	public MarketCarInfoChe300 getCarInfobySerial(String serial) throws TmsDaoException {
		PreparedStatement ps = null; ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT	 ");
		sql.append("	A.ID, ");
		sql.append("	A.VIN, ");
		sql.append("	B.VENDORNAME, ");
		sql.append("	C.BRANDNAME, ");
		sql.append("	D.STYLENAME, ");
		sql.append("	D.`YEAR`, ");
		sql.append("	D.EXHAUST, ");
		sql.append("	D.EMISSIONSTANGARD, ");
		sql.append("	D.GEARBOX, ");
		sql.append("	A.PRICE/10000 as PRICE, ");
		sql.append("	A.MILEAGE, ");
		sql.append("	A.REGDATE, ");
		sql.append("	A.JQX, ");
		sql.append("	A.YEARCAREFULPERIOD, ");
		sql.append("	DATE_FORMAT(A.INSERTTIME,'%Y-%m-%d %H:%i:%s') AS INSERTTIME, ");
		sql.append("	A.ISSHELVE, ");
		sql.append("	A.COLOR, ");
		sql.append("	A.COMPANYCONTACTPERSON, ");
		sql.append("	A.COMPANYCONTACTPHONE, ");
		sql.append("	A.PHOTO_1, ");
		sql.append("	A.PHOTO_2, ");
		sql.append("	A.PHOTO_3, ");
		sql.append("	A.PHOTO_4, ");
		sql.append("	A.PHOTO_5, ");
		sql.append("	A.PHOTO_6, ");
		sql.append("	A.PHOTO_7, ");
		sql.append("	A.PHOTO_8, ");
		sql.append("	A.ATTESTSTATUS, ");
		sql.append("	A.CARTYPE ");
		sql.append(" FROM	 ");
		sql.append("	"+TmsTableNames.TMS_MARKET_CAR_INFO+" A, ");
		sql.append("	"+TmsTableNames.TMS_VENDOR+" B, ");
		sql.append("	"+TmsTableNames.TMS_VEHICLE_BRAND+" C, ");
		sql.append("	"+TmsTableNames.TMS_CAR_STYLE+" D ");
		sql.append(" WHERE	 ");
		sql.append("	SERIAL = ? ");
		sql.append(" AND A.VENDORID = B.ID	 ");
		sql.append(" AND A.BRANDID = C.ID	 ");
		sql.append(" AND A.CARSTYLEID = D.ID	 ");
		MarketCarInfoChe300 info = null;
		try {
			
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, serial);
			rs = ps.executeQuery();
			while(rs.next()){
				info = new MarketCarInfoChe300();
				info.setCarId(rs.getString("ID"));
				info.setOperation("add");
				info.setSellerType(2);//车商车
				info.setVin(rs.getString("VIN"));
				info.setBrand(rs.getString("VENDORNAME"));
				info.setSeries(rs.getString("BRANDNAME"));
				info.setModel(rs.getString("STYLENAME"));
				info.setModelYear(rs.getInt("YEAR"));
				info.setLiter(rs.getString("EXHAUST"));
				String emission = rs.getString("EMISSIONSTANGARD");
				if(StringUtil.isNotBlank(emission)) info.setEmissionStandard(emission);
				else info.setEmissionStandard("国IV");
				info.setGearType(rs.getString("GEARBOX"));
				info.setPrice(rs.getInt("PRICE"));
				info.setMileage(rs.getInt("MILEAGE"));
				info.setRegisterDate(rs.getString("REGDATE"));
				info.setInsuranceDate("已过期");
				info.setTlciDate(rs.getString("JQX"));
				info.setAuditDate(rs.getString("YEARCAREFULPERIOD"));
				info.setPostTime(rs.getString("INSERTTIME"));
				String isShelve = rs.getString("ISSHELVE");
				if("1".equals(isShelve)) info.setStatus("在售");
				if("2".equals(isShelve)) info.setStatus("下架");
				else info.setStatus("已售");
				info.setColor(rs.getInt("COLOR"));
				info.setTransferTimes(0);
				info.setContactor(rs.getString("COMPANYCONTACTPHONE"));
				info.setPhone(rs.getString("COMPANYCONTACTPHONE"));
				info.setCarUrl("#");
				info.setPictures1(rs.getString("PHOTO_1"));
				info.setPictures2(rs.getString("PHOTO_2"));
				info.setPictures3(rs.getString("PHOTO_3"));
				info.setPictures4(rs.getString("PHOTO_4"));
				info.setPictures5(rs.getString("PHOTO_5"));
				info.setPictures6(rs.getString("PHOTO_6"));
				info.setPictures7(rs.getString("PHOTO_7"));
				info.setPictures8(rs.getString("PHOTO_8"));
				String attestStatus = rs.getString("attestStatus");
				if("2".equals(attestStatus)) info.setInspectStatus(true);
				else info.setInspectStatus(false);
				info.setCarType(rs.getInt("CARTYPE"));
				info.setCarNo(serial);
				break;
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
		return info;
	}
	

	@Override
	public TroubleCarInfoDto getTroubleCarInfobyVin(String vin) throws TmsDaoException {
		PreparedStatement ps = null; ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append(" SELECT	 ");
		sql.append("	ID, ");
		sql.append("	VIN, ");
		sql.append("	TROUBLETYPE, ");
		sql.append("	REMARK, ");
		sql.append("	INSERTTIME ");
		sql.append(" FROM	 ");
		sql.append(TmsTableNames.TMS_TROUBLE_CAR_INFO);
		sql.append(" WHERE	 ");
		sql.append("	VIN = ? ");
		sql.append(" ORDER BY ID DESC");
		TroubleCarInfoDto info = null;
		try {
			
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, vin);
			rs = ps.executeQuery();
			while(rs.next()){
				info = new TroubleCarInfoDto();
				info.setId(rs.getInt("ID"));
				info.setVin(rs.getString("VIN"));
				info.setTroubleType(rs.getInt("TROUBLETYPE"));
				info.setRemark(rs.getString("REMARK"));
				info.setInsertTime(rs.getTimestamp("INSERTTIME"));
				break;
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
		return info;
	}


	@Override
	public void insertBaseCarInfo(BaseCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("INSERT INTO ");
			sql.append(TmsTableNames.TMS_BASE_CAR_INFO);
			sql.append("(");
			sql.append(" VIN, ");
			sql.append(" COUNTRYSTYLE, ");
			sql.append(" CARUSE, ");
			sql.append(" CARDTYPE, ");
			sql.append(" REGISTERCARDNO, ");
			sql.append(" CAROWNER, ");
			sql.append(" OWNERADDRESS, ");
			sql.append(" OWNERPHONE, ");
			sql.append(" CAROWNERIDCARDNO, ");
			sql.append(" OWNERORGNO, ");
			sql.append(" MODELCODE, ");
			sql.append(" VENDORCODE, ");
			sql.append(" CARNAME, ");
			sql.append(" VENDORID, ");
			sql.append(" BRANDID, ");
			sql.append(" CARSTYLEID, ");
			sql.append(" OWNERTYPE, ");
			sql.append(" CARTYPE, ");
			sql.append(" insertTime ");
			sql.append("  ) VALUES ( ");
			sql.append(" ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,SYSDATE() )");
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, dto.getVin());
			ps.setInt(2, dto.getCountryStyle());
			ps.setInt(3, dto.getCarUse());
			ps.setInt(4, dto.getCardType());
			ps.setString(5, dto.getRegisterCardNo());
			ps.setString(6, dto.getCarOwner());
			ps.setString(7, dto.getOwnerAddress());
			ps.setString(8, dto.getOwnerPhone());
			ps.setString(9, dto.getCarOwnerIdCardNo());
			ps.setString(10, dto.getOwnerOrgNo());
			ps.setString(11, dto.getModelCode());
			ps.setString(12, dto.getVendorCode());
			ps.setString(13, dto.getCarName());
			ps.setString(14, dto.getVendorId());
			ps.setString(15, dto.getBrandId());
			ps.setString(16, dto.getCarStyleId());
			ps.setInt(17, dto.getOwnerType());
			ps.setInt(18, dto.getCarType());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
	}


	@Override
	public void updateBaseCarInfo(BaseCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer();
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_BASE_CAR_INFO );
		sql.append(" SET ");
		sql.append(" COUNTRYSTYLE=?,");
		sql.append(" CARUSE=?,");
		sql.append(" CARDTYPE=?,");
		sql.append(" REGISTERCARDNO=?,");
		sql.append(" CAROWNER=?,");
		sql.append(" OWNERADDRESS=?,");
		sql.append(" OWNERPHONE=?,");
		sql.append(" CAROWNERIDCARDNO=?,");
		sql.append(" OWNERORGNO=?,");
		sql.append(" MODELCODE=?,");
		sql.append(" VENDORCODE=?,");
		sql.append(" CARNAME=?,");
		sql.append(" VENDORID=?,");		
		sql.append(" BRANDID=?,");		
		sql.append(" CARSTYLEID=?,");	
		sql.append(" OWNERTYPE=?, ");
		sql.append(" CARTYPE=? ");
		sql.append(" WHERE");
		sql.append(" VIN=?");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setInt(1, dto.getCountryStyle());
			ps.setInt(2, dto.getCarUse());
			ps.setInt(3, dto.getCardType());
			ps.setString(4, dto.getRegisterCardNo());
			ps.setString(5, dto.getCarOwner());
			ps.setString(6, dto.getOwnerAddress());
			ps.setString(7, dto.getOwnerPhone());
			ps.setString(8, dto.getCarOwnerIdCardNo());
			ps.setString(9, dto.getOwnerOrgNo());
			ps.setString(10, dto.getModelCode());
			ps.setString(11, dto.getVendorCode());
			ps.setString(12, dto.getCarName());
			ps.setString(13, dto.getVendorId());
			ps.setString(14, dto.getBrandId());
			ps.setString(15, dto.getCarStyleId());
			ps.setInt(16, dto.getOwnerType());
			ps.setInt(17, dto.getCarType());
			ps.setString(18, dto.getVin());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			close(rs, ps);
		}
	}


	@Override
	public List<MarketCarInfoDto> findCarOwnerByCardNo(String ownerCardNo) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ID,");
		sql.append(" CAROWNER,");
		sql.append(" OWNERPHONE,");
		sql.append(" OWNERCARDNO,");
		sql.append(" OWNERADDRESS,");
		sql.append(" OWNERTYPE");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_CAR_OWNER);
		sql.append(" WHERE OWNERCARDNO LIKE '%");
		sql.append(ownerCardNo);
		sql.append("%'");
		sql.append(" ORDER BY OWNERCARDNO ASC LIMIT 30");
		try {
			ps = conn.prepareStatement(sql.toString());		
			rs = ps.executeQuery();
			List<MarketCarInfoDto> r = new ArrayList<MarketCarInfoDto>();
			while (rs.next()) {
				MarketCarInfoDto marketCarInfoDto =  new MarketCarInfoDto();
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerCardNo(rs.getString("OWNERCARDNO"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));
				marketCarInfoDto.setOwnerType(rs.getInt("OWNERTYPE"));
				r.add(marketCarInfoDto);
			}
			return r;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}


	@Override
	public List<MarketCarInfoDto> findCarOwnerByName(String name) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ID,");
		sql.append(" CAROWNER,");
		sql.append(" OWNERPHONE,");
		sql.append(" OWNERCARDNO,");
		sql.append(" OWNERADDRESS,");
		sql.append(" OWNERTYPE");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_CAR_OWNER);
		sql.append(" WHERE CAROWNER LIKE '%");
		sql.append(name);
		sql.append("%'");
		sql.append(" ORDER BY OWNERCARDNO ASC LIMIT 30");
		try {
			ps = conn.prepareStatement(sql.toString());		
			rs = ps.executeQuery();
			List<MarketCarInfoDto> r = new ArrayList<MarketCarInfoDto>();
			while (rs.next()) {
				MarketCarInfoDto marketCarInfoDto =  new MarketCarInfoDto();
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerCardNo(rs.getString("OWNERCARDNO"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));
				marketCarInfoDto.setId(rs.getInt("OWNERTYPE"));
				r.add(marketCarInfoDto);
			}
			return r;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}

	

	@Override
	public MarketCarInfoDto getCarOwnerById(String id) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT ID,");
		sql.append(" CAROWNER,");
		sql.append(" OWNERPHONE,");
		sql.append(" OWNERCARDNO,");
		sql.append(" OWNERADDRESS,");
		sql.append(" OWNERTYPE");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_CAR_OWNER);
		sql.append(" WHERE ID = '");
		sql.append(id);
		sql.append("'");
		try {
			ps = conn.prepareStatement(sql.toString());		
			rs = ps.executeQuery();
			MarketCarInfoDto marketCarInfoDto =  new MarketCarInfoDto();
			while (rs.next()) {
				marketCarInfoDto.setId(rs.getInt("ID"));
				marketCarInfoDto.setCarOwner(rs.getString("CAROWNER"));
				marketCarInfoDto.setOwnerPhone(rs.getString("OWNERPHONE"));
				marketCarInfoDto.setOwnerCardNo(rs.getString("OWNERCARDNO"));
				marketCarInfoDto.setOwnerAddress(rs.getString("OWNERADDRESS"));
				marketCarInfoDto.setId(rs.getInt("OWNERTYPE"));
			}
			return marketCarInfoDto;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}


	@Override
	public void updateCarOwnerByOwnerCardNo(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_CAR_OWNER);
		sql.append(" SET ");
		sql.append(" CAROWNER=?,  ");
		sql.append(" OWNERPHONE=?,  ");
		sql.append(" OWNERADDRESS=?, ");
		sql.append(" OWNERTYPE=? ");
		sql.append(" WHERE  ");
		sql.append(" OWNERCARDNO=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, dto.getCarOwner());
			ps.setString(2, dto.getOwnerPhone());
			ps.setString(3, dto.getOwnerAddress());
			ps.setInt(4, dto.getOwnerType());
			ps.setString(5, dto.getOwnerCardNo());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}
	
	@Override
	public void updateCarByVin(String vin, String regDate) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("");
		sql.append("UPDATE ");
		sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
		sql.append(" SET ");
		sql.append(" regDate=?  ");
		sql.append(" WHERE  ");
		sql.append(" vin=? ");
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, regDate);
			ps.setString(2, vin);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		}finally {
			super.close(rs, ps);
		}
	}


	public void insertCarOwner(MarketCarInfoDto dto) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			StringBuffer sql = new StringBuffer("INSERT INTO ");
			sql.append(TmsTableNames.TMS_CAR_OWNER);
			sql.append("(");
			sql.append(" CAROWNER, ");
			sql.append(" OWNERPHONE, ");			
			sql.append(" OWNERCARDNO, ");
			sql.append(" OWNERADDRESS, ");
			sql.append(" OWNERTYPE ");
			sql.append("  ) VALUES ( ");
			sql.append(" ?,?,?,?,?)");
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, dto.getCarOwner());
			ps.setString(2, dto.getOwnerPhone());
			ps.setString(3, dto.getOwnerCardNo());
			ps.setString(4, dto.getOwnerAddress());
			ps.setInt(5, dto.getOwnerType());
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());
		} finally {
			super.close(rs, ps);
		}
	}

	@Override
	public MarketCarInfoDto getCtiyInfo(String cityId) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append(" ID,");
		sql.append(" provinceId,cityId,proName,cityName,vaoName ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_CITY);
		sql.append(" WHERE ");
		sql.append(" cityId = '"+cityId+"'");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				dto.setPrivilId(rs.getString("provinceId"));
				dto.setCityId(rs.getString("cityId"));
				dto.setProName(rs.getString("proName"));
				dto.setCityName(rs.getString("cityName"));
				dto.setVaoName(rs.getString("vaoName"));
				return dto;
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
		return null;	
	}
	

	@Override
	public List<MarketCarInfoDto> getVaoNameInfoList(String py) throws TmsDaoException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<MarketCarInfoDto> list = new ArrayList<MarketCarInfoDto>();
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append(" ID,");
		sql.append(" cityid,");
		sql.append(" VAONAME ");
		sql.append("FROM ");
		sql.append(TmsTableNames.TMS_CITY);
		sql.append(" WHERE ");
		sql.append(" CITYPY LIKE '%" + py +"%'");
		sql.append(" ORDER BY VAONAME ASC");
		sql.append(" LIMIT 30 ");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while(rs.next()){
				MarketCarInfoDto dto = new MarketCarInfoDto();
				dto.setId(rs.getInt("ID"));
				dto.setCityId(rs.getString("cityid"));
				dto.setVaoName(rs.getString("VAONAME"));
				list.add(dto);
			}
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}	
		return list;
	}
   public void updateMarketCarInfoByVin(MarketCarInfoDto marketCarInfoDto) throws TmsDaoException{
        PreparedStatement ps = null;
        ResultSet rs = null;
        StringBuffer sql = new StringBuffer("");
        sql.append("UPDATE ");
        sql.append(TmsTableNames.TMS_MARKET_CAR_INFO);
        sql.append(" SET ");
        sql.append(" LICENSEPLATE=? ,");
        sql.append(" CHGLICENSEPLATETIME=SYSDATE() ");
        sql.append(" WHERE ");
        sql.append(" VIN=? ");
        try {
            ps = conn.prepareStatement(sql.toString());
            ps.setString(1, marketCarInfoDto.getLicensePlate());
            ps.setString(2,marketCarInfoDto.getVin());

            ps.executeUpdate();
        } catch (SQLException e) {
            throw new TmsDaoException(e.toString());
        }finally {
            super.close(rs, ps);
        }
    }
}